使用线串裁剪多边形

时间:2019-10-03 19:42:27

标签: r sf

我试图找出如何基于线串裁剪多边形的方法。我已经估计了陆生动物的射程,并且这个射程估计延伸到了海洋。我想剪掉延伸到海洋中的任何部分。

我正在使用rnaturalearth来获取海岸线,该海岸线返回一系列线串

library(lwgeom)
library(rnaturalearth)
library(rnaturalearthhires)
library(sf)

cl10 <- ne_coastline(scale=10,returnclass='sf')

poly1是原始范围估计值的sf多边形。 (要从下面的wkt加载此文件,您需要添加最终的')“',由于某种原因,它没有显示。)

wkt <- "SRID=4326;POLYGON((-64.73304 10.46291,-64.73375 10.46797,-64.73479 10.47601,-64.73529 10.48397,-64.73576 10.49193,-64.73613 10.49987,-64.73632 10.50779,-64.73639 10.51569,-64.73616 10.52355,-64.73585 10.5314,-64.73544 10.53924,-64.73476 10.54703,-64.73389 10.5548,-64.73279 10.56254,-64.7315 10.57025,-64.72998 10.57793,-64.7282 10.58557,-64.72634 10.5932,-64.72428 10.6008,-64.72188 10.60836,-64.71932 10.61589,-64.7167 10.62341,-64.71385 10.6309,-64.71074 10.63836,-64.70741 10.64578,-64.7061 10.64831,-64.70363 10.65314,-64.69975 10.66049,-64.6955 10.66779,-64.69131 10.67509,-64.68678 10.68235,-64.68541 10.68422,-64.6816 10.68951,-64.6763 10.69666,-64.67129 10.70384,-64.66619 10.71008,-64.6655 10.71092,-64.65921 10.71793,-64.65313 10.72497,-64.64775 10.73055,-64.64641 10.73191,-64.63922 10.7388,-64.63234 10.74572,-64.62976 10.74793,-64.62443 10.7525,-64.61667 10.7593,-64.61211 10.76288,-64.6081 10.76599,-64.59965 10.77269,-64.59471 10.77621,-64.59032 10.77927,-64.58079 10.78582,-64.57753 10.78797,-64.57081 10.79231,-64.56069 10.79877,-64.56047 10.7989,-64.54971 10.80512,-64.54362 10.80837,-64.53795 10.81135,-64.52681 10.81755,-64.52662 10.81765,-64.51376 10.82373,-64.5102 10.82536,-64.50063 10.82977,-64.49363 10.83293,-64.48692 10.83573,-64.47717 10.83971,-64.4725 10.84159,-64.46074 10.84626,-64.45774 10.8474,-64.4444 10.85221,-64.44196 10.85306,-64.42813 10.85767,-64.42525 10.8586,-64.41193 10.86269,-64.40758 10.86399,-64.39577 10.86735,-64.38903 10.86927,-64.37966 10.87175,-64.36964 10.87442,-64.36356 10.876,-64.34914 10.87941,-64.34754 10.87978,-64.33158 10.88309,-64.32668 10.88413,-64.31564 10.88629,-64.3033 10.88871,-64.29971 10.88941,-64.28386 10.89201,-64.27782 10.89299,-64.26801 10.89454,-64.25219 10.89691,-64.2509 10.89707,-64.23644 10.89877,-64.22147 10.90079,-64.22066 10.9009,-64.20497 10.90236,-64.18942 10.90414,-64.18923 10.90416,-64.17358 10.90532,-64.15793 10.90653,-64.15312 10.90687,-64.1423 10.9076,-64.12671 10.90837,-64.11307 10.90908,-64.11112 10.90917,-64.09558 10.90962,-64.08004 10.91004,-64.06644 10.91034,-64.06452 10.91038,-64.04903 10.91044,-64.03357 10.91035,-64.0181 10.91033,-64.01038 10.91024,-64.00265 10.91018,-63.98724 10.90971,-63.97184 10.90917,-63.95645 10.90859,-63.94106 10.90802,-63.93825 10.90785,-63.92572 10.90714,-63.91037 10.90623,-63.89506 10.90515,-63.87976 10.90399,-63.86445 10.9028,-63.84918 10.90147,-63.83391 10.90008,-63.81903 10.8987,-63.81864 10.89867,-63.80341 10.89699,-63.7882 10.89524,-63.77299 10.89341,-63.75779 10.89158,-63.7426 10.88963,-63.72743 10.88756,-63.71228 10.88539,-63.69713 10.88315,-63.682 10.88083,-63.66689 10.87837,-63.65179 10.87589,-63.63669 10.87336,-63.6216 10.87073,-63.61213 10.86901,-63.60653 10.86801,-63.59148 10.86514,-63.57644 10.86224,-63.56141 10.85928,-63.54637 10.85631,-63.53137 10.85314,-63.51636 10.85002,-63.50136 10.84683,-63.48638 10.84351,-63.48076 10.84219,-63.47142 10.84005,-63.45647 10.83653,-63.44153 10.83301,-63.4266 10.82935,-63.41166 10.82575,-63.39778 10.82232,-63.39674 10.82206,-63.38185 10.81815,-63.36696 10.81424,-63.35207 10.81034,-63.3372 10.80631,-63.33254 10.80498,-63.32234 10.80218,-63.30749 10.79802,-63.29265 10.79381,-63.27782 10.78953,-63.27544 10.78881,-63.263 10.78512,-63.24821 10.78062,-63.23339 10.77621,-63.22532 10.77365,-63.21862 10.77158,-63.20383 10.767,-63.18906 10.76236,-63.17885 10.759,-63.17431 10.75754,-63.15955 10.75275,-63.14481 10.74792,-63.13611 10.74489,-63.1301 10.74286,-63.11538 10.73783,-63.10067 10.73277,-63.0963 10.73121,-63.08598 10.7276,-63.07129 10.72239,-63.05827 10.71777,-63.0566 10.71719,-63.04194 10.7118,-63.02729 10.70637,-63.02302 10.70474,-63.01265 10.70089,-62.99799 10.69546,-62.98886 10.69186,-62.98338 10.68977,-62.96876 10.68412,-62.95604 10.67917,-62.95415 10.67845,-62.93956 10.67261,-62.92496 10.66686,-62.92449 10.66666,-62.91039 10.66088,-62.89582 10.65498,-62.89434 10.65436,-62.88127 10.64888,-62.86671 10.64284,-62.86525 10.6422,-62.85219 10.63661,-62.83765 10.63045,-62.83703 10.63017,-62.82315 10.62408,-62.80972 10.61828,-62.80863 10.61781,-62.79415 10.6113,-62.78359 10.60655,-62.77966 10.60483,-62.76517 10.59834,-62.75771 10.59486,-62.75071 10.5917,-62.73626 10.58505,-62.73248 10.58325,-62.72181 10.57832,-62.70751 10.57169,-62.70736 10.57162,-62.69295 10.56463,-62.68404 10.56034,-62.67853 10.55777,-62.66412 10.55078,-62.66045 10.54898,-62.64972 10.54377,-62.63741 10.53769,-62.63533 10.53669,-62.62095 10.52957,-62.61505 10.5265,-62.6066 10.52224,-62.59248 10.51528,-62.59221 10.51515,-62.57788 10.50774,-62.57134 10.50427,-62.56355 10.50026,-62.54973 10.49319,-62.54921 10.49291,-62.53488 10.48542,-62.52902 10.48223,-62.52059 10.47776,-62.50833 10.47128,-62.50628 10.4702,-62.49198 10.46256,-62.48799 10.46038,-62.47771 10.45474,-62.46826 10.44957,-62.46343 10.44698,-62.44915 10.43922,-62.44823 10.43871,-62.43489 10.43133,-62.42892 10.42796,-62.42065 10.42334,-62.40985 10.41724,-62.40641 10.41534,-62.39216 10.40741,-62.39054 10.40649,-62.37794 10.39929,-62.37191 10.39583,-62.36372 10.39116,-62.35334 10.38518,-62.34951 10.38301,-62.33529 10.37489,-62.33463 10.37451,-62.32108 10.3667,-62.31637 10.36391,-62.30691 10.3583,-62.29852 10.35336,-62.29272 10.35002,-62.28024 10.34275,-62.27852 10.34175,-62.26434 10.33344,-62.26222 10.33218,-62.25017 10.32501,-62.24453 10.32165,-62.236 10.31657,-62.2268 10.31112,-62.22183 10.3082,-62.20897 10.30057,-62.20766 10.2998,-62.19349 10.29139,-62.19126 10.29004,-62.17934 10.28291,-62.17367 10.27953,-62.16518 10.27442,-62.1561 10.26902,-62.15101 10.26602,-62.13829 10.25847,-62.13685 10.25762,-62.12268 10.24922,-62.12053 10.24792,-62.10853 10.24076,-62.10291 10.2374,-62.09437 10.2323,-62.08513 10.22685,-62.0802 10.22397,-62.06689 10.21623,-62.06601 10.21572,-62.05185 10.20731,-62.04914 10.20569,-62.03767 10.19903,-62.03092 10.19507,-62.02349 10.19073,-62.01251 10.18443,-62.00929 10.18259,-61.99507 10.17458,-61.99352 10.17369,-61.98087 10.16643,-61.97491 10.16301,-61.96667 10.15833,-61.95575 10.15225,-61.95243 10.15042,-61.93818 10.14263,-61.93598 10.1414,-61.92394 10.13476,-61.91622 10.13054,-61.90969 10.12701,-61.89539 10.11953,-61.89538 10.11953,-61.88112 10.11185,-61.87506 10.10859,-61.86685 10.10421,-61.85337 10.09744,-61.85251 10.09701,-61.8382 10.08965,-61.83157 10.08627,-61.82387 10.08238,-61.8095 10.07537,-61.80865 10.07494,-61.79516 10.06823,-61.7856 10.06359,-61.78078 10.0613,-61.76637 10.0546,-61.76101 10.052,-61.75198 10.04772,-61.73753 10.04123,-61.73543 10.04026,-61.72311 10.03459,-61.7087 10.02835,-61.70864 10.02832,-61.6942 10.02178,-61.68151 10.01636,-61.67971 10.01561,-61.66523 10.00934,-61.65243 10.00409,-61.6507 10.0034,-61.6362 9.997307,-61.62164 9.99159,-61.62152 9.991541,-61.60713 9.985571,-61.59255 9.979943,-61.59 9.978896,-61.57801 9.974096,-61.56341 9.968638,-61.55666 9.965975,-61.54884 9.962998,-61.53424 9.957559,-61.52083 9.952675,-61.51962 9.952241,-61.50503 9.94675,-61.49039 9.941541,-61.48417 9.939246,-61.47577 9.936246,-61.46114 9.930998,-61.44647 9.925975,-61.44499 9.925432,-61.43184 9.920747,-61.41718 9.9157,-61.40508 9.911503,-61.40253 9.910635,-61.38788 9.905512,-61.37319 9.900693,-61.36373 9.897351,-61.35854 9.895561,-61.34387 9.890574,-61.3292 9.885642,-61.32195 9.883129,-61.31453 9.880637,-61.29986 9.875668,-61.28519 9.870744,-61.27963 9.86882,-61.27052 9.865749,-61.25586 9.860781,-61.24118 9.855888,-61.23711 9.854474,-61.22652 9.85087,-61.21187 9.845786,-61.19718 9.840917,-61.19522 9.840219,-61.18254 9.835801,-61.16788 9.830773,-61.15422 9.826093,-61.15323 9.825755,-61.1386 9.820518,-61.12394 9.815556,-61.11459 9.812168,-61.10932 9.810305,-61.0947 9.805046,-61.08007 9.799867,-61.0761 9.798413,-61.06545 9.794565,-61.05085 9.78923,-61.03888 9.784847,-61.03624 9.783904,-61.02166 9.778431,-61.00706 9.773077,-61.00293 9.77147,-60.99249 9.767492,-60.97791 9.762033,-60.96837 9.7583,-60.96335 9.756394,-60.9488 9.750703,-60.93426 9.745196,-60.93423 9.745184,-60.91972 9.739281,-60.90518 9.733539,-60.90262 9.732464,-60.89068 9.727559,-60.87616 9.721668,-60.872 9.719885,-60.86168 9.715605,-60.84717 9.709654,-60.842 9.707398,-60.83271 9.703463,-60.81823 9.697355,-60.81315 9.695084,-60.80379 9.691013,-60.78933 9.684754,-60.78533 9.682925,-60.77491 9.678298,-60.76049 9.671856,-60.75845 9.670908,-60.7461 9.665213,-60.7321 9.65897,-60.73167 9.658779,-60.71732 9.651903,-60.70756 9.647305,-60.70294 9.645179,-60.68855 9.638528,-60.68272 9.635594,-60.67423 9.631448,-60.65988 9.624584,-60.65873 9.624011,-60.64557 9.61742,-60.63594 9.61261,-60.63126 9.610311,-60.61696 9.603115,-60.61339 9.601244,-60.60269 9.595709,-60.59153 9.589984,-60.58841 9.588402,-60.57415 9.580942,-60.57023 9.578807,-60.55993 9.573282,-60.54972 9.56775,-60.5457 9.565604,-60.53148 9.557961,-60.52921 9.556691,-60.5173 9.550029,-60.50987 9.545813,-60.50313 9.542042,-60.49044 9.534919,-60.48895 9.534081,-60.47481 9.525925,-60.47183 9.524149,-60.46069 9.517625,-60.45374 9.513459,-60.44659 9.509217,-60.43578 9.502788,-60.43248 9.50082,-60.4184 9.492318,-60.41815 9.492165,-60.40434 9.483605,-60.40132 9.481666,-60.39031 9.474767,-60.38466 9.471192,-60.3763 9.465832,-60.36857 9.460806,-60.3623 9.456769,-60.35256 9.450432,-60.34831 9.447676,-60.33671 9.440079,-60.33434 9.438494,-60.32149 9.429825,-60.3204 9.429087,-60.30646 9.419666,-60.30634 9.41958,-60.29257 9.409966,-60.2918 9.409429,-60.2787 9.400191,-60.27746 9.399307,-60.26484 9.390272,-60.26347 9.389241,-60.25107 9.379837,-60.25035 9.379307,-60.23727 9.369608,-60.23688 9.369319,-60.22353 9.359348,-60.22347 9.359308,-60.21077 9.349469,-60.20974 9.348667,-60.1981 9.339603,-60.19601 9.337965,-60.18581 9.329795,-60.18233 9.32698,-60.17361 9.320001,-60.16866 9.315952,-60.16169 9.31025,-60.15501 9.304783,-60.14981 9.300504,-60.14138 9.293462,-60.13819 9.290799,-60.12779 9.281922,-60.12688 9.28114,-60.11608 9.27156,-60.11427 9.26995,-60.10532 9.261987,-60.10077 9.257853,-60.09468 9.252432,-60.08726 9.245799,-60.08403 9.242874,-60.07381 9.2334,-60.07379 9.233381,-60.06412 9.223975,-60.06046 9.220393,-60.05442 9.214564,-60.04711 9.207419,-60.04475 9.205157,-60.03548 9.195813,-60.03381 9.194076,-60.02643 9.186502,-60.02054 9.180567,-60.01712 9.177151,-60.00845 9.167899,-60.00733 9.166661,-60.00008 9.158693,-59.9942 9.152287,-59.99151 9.149456,-59.98346 9.1403,-59.98113 9.137586,-59.97541 9.131143,-59.96807 9.122774,-59.96738 9.121988,-59.95999 9.112935,-59.95513 9.10723,-59.9521 9.103803,-59.94515 9.094816,-59.94227 9.091182,-59.93789 9.085782,-59.93084 9.076779,-59.92945 9.074836,-59.92431 9.067857,-59.91741 9.058879,-59.91674 9.057898,-59.9111 9.049991,-59.90461 9.041076,-59.90412 9.040324,-59.89875 9.032259,-59.89263 9.0234,-59.89166 9.021814,-59.88706 9.014628,-59.88132 9.005828,-59.87932 9.002556,-59.87579 8.997061,-59.87057 8.988344,-59.86712 8.982396,-59.86547 8.979644,-59.86056 8.970973,-59.85553 8.962285,-59.85506 8.96136,-59.85105 8.953681,-59.84658 8.945079,-59.84328 8.93859,-59.84219 8.93649,-59.83827 8.927974,-59.83428 8.919446,-59.8318 8.913986,-59.83032 8.910925,-59.82676 8.902464,-59.82329 8.894018,-59.82061 8.887526,-59.81977 8.885564,-59.81674 8.877187,-59.8138 8.868823,-59.81079 8.860449,-59.80996 8.857668,-59.80819 8.852137,-59.80582 8.843862,-59.80346 8.83559,-59.80117 8.827328,-59.8001 8.822896,-59.79912 8.819102,-59.79725 8.810907,-59.79569 8.802758,-59.79427 8.794631,-59.7929 8.786513,-59.79169 8.779063,-59.79157 8.7784,-59.79072 8.770362,-59.78986 8.762324,-59.78943 8.754351,-59.78887 8.746359,-59.7887 8.738428,-59.78843 8.73048,-59.78862 8.722606,-59.78885 8.714736,-59.78924 8.706892,-59.78982 8.699077,-59.79062 8.691298,-59.79158 8.683543,-59.79283 8.675833,-59.79433 8.668163,-59.796 8.660518,-59.79793 8.652914,-59.80006 8.645342,-59.80233 8.637792,-59.80473 8.630261,-59.8076 8.622805,-59.81042 8.61534,-59.81348 8.607913,-59.8168 8.600525,-59.82026 8.59316,-59.82173 8.590491,-59.82426 8.585879,-59.8284 8.57862,-59.83288 8.571415,-59.83719 8.564181,-59.84206 8.557036,-59.84255 8.556397,-59.84738 8.549962,-59.85295 8.542925,-59.85856 8.535895,-59.86182 8.531992,-59.86439 8.5289,-59.87096 8.522018,-59.87739 8.515115,-59.88035 8.512257,-59.88442 8.508307,-59.8916 8.50152,-59.89846 8.495194,-59.89894 8.49476,-59.90745 8.48818,-59.91534 8.481505,-59.91611 8.480966,-59.92454 8.475032,-59.93315 8.468469,-59.93352 8.468237,-59.94303 8.462103,-59.95068 8.457075,-59.95281 8.45572,-59.96335 8.449455,-59.96767 8.446971,-59.9744 8.44327,-59.98454 8.437626,-59.98551 8.437093,-59.99773 8.431089,-60.00122 8.429466,-60.01038 8.425151,-60.01783 8.421737,-60.02355 8.419294,-60.03434 8.414641,-60.03712 8.413498,-60.05079 8.407928,-60.05118 8.407778,-60.06655 8.402262,-60.0671 8.40207,-60.08257 8.396844,-60.08335 8.396588,-60.09931 8.391539,-60.09955 8.391468,-60.11565 8.386966,-60.11751 8.386458,-60.1317 8.382737,-60.13651 8.381502,-60.14772 8.378738,-60.15622 8.376653,-60.16369 8.375004,-60.17752 8.372051,-60.17961 8.371606,-60.19546 8.368661,-60.20054 8.367714,-60.21128 8.365889,-60.22469 8.363549,-60.2271 8.363133,-60.24281 8.361066,-60.25156 8.359805,-60.25854 8.358832,-60.27421 8.357012,-60.28009 8.356314,-60.28988 8.355213,-60.30547 8.353862,-60.31165 8.353291,-60.32107 8.352488,-60.3366 8.351552,-60.34694 8.350841,-60.35215 8.350489,-60.36761 8.349978,-60.38311 8.349196,-60.38672 8.349081,-60.39857 8.348733,-60.41396 8.34863,-60.42941 8.348205,-60.43238 8.348222,-60.44478 8.348302,-60.4601 8.348646,-60.47546 8.348801,-60.48958 8.349137,-60.49078 8.349162,-60.50607 8.349757,-60.52133 8.350551,-60.53657 8.351422,-60.55181 8.35234,-60.56705 8.353243,-60.56826 8.353347,-60.58223 8.354513,-60.5974 8.355799,-60.61255 8.357305,-60.62767 8.358933,-60.64279 8.360605,-60.6579 8.362359,-60.673 8.364125,-60.68807 8.366088,-60.70312 8.36823,-60.71816 8.370405,-60.73318 8.372689,-60.74819 8.375073,-60.76319 8.377516,-60.77817 8.380075,-60.79312 8.382838,-60.80806 8.385652,-60.823 8.388466,-60.83791 8.391453,-60.85282 8.394445,-60.86772 8.397519,-60.88259 8.400786,-60.89328 8.403199,-60.89745 8.404125,-60.91228 8.407674,-60.92711 8.411204,-60.94193 8.414806,-60.95675 8.418429,-60.97154 8.422183,-60.97937 8.424254,-60.98632 8.426057,-61.00108 8.430073,-61.01582 8.434144,-61.03057 8.43819,-61.04403 8.442022,-61.0453 8.442378,-61.06 8.446784,-61.07469 8.451253,-61.08938 8.45568,-61.09653 8.457925,-61.10405 8.460222,-61.1187 8.464963,-61.13337 8.469533,-61.14367 8.473004,-61.14799 8.474436,-61.16259 8.479449,-61.17723 8.484284,-61.18571 8.487301,-61.19181 8.489429,-61.20638 8.494624,-61.22097 8.499763,-61.2246 8.501115,-61.23552 8.505124,-61.25007 8.510523,-61.26054 8.514476,-61.2646 8.515997,-61.27911 8.521607,-61.29364 8.527151,-61.29461 8.527549,-61.30811 8.53304,-61.32262 8.538679,-61.32637 8.54027,-61.33707 8.544705,-61.35155 8.550573,-61.3567 8.552769,-61.366 8.556609,-61.38043 8.562742,-61.38571 8.565066,-61.39485 8.56896,-61.40927 8.575185,-61.41367 8.577202,-61.42366 8.581633,-61.43807 8.587938,-61.44078 8.589207,-61.45244 8.594548,-61.46683 8.600956,-61.46712 8.601093,-61.48117 8.607758,-61.49191 8.612743,-61.49553 8.614386,-61.50987 8.621131,-61.51657 8.624371,-61.52419 8.628053,-61.53852 8.634882,-61.54055 8.635894,-61.55281 8.641982,-61.56365 8.647283,-61.56712 8.648972,-61.58142 8.656042,-61.58636 8.658612,-61.59567 8.663394,-61.6089 8.669913,-61.60997 8.670443,-61.62423 8.677782,-61.63042 8.68106,-61.63846 8.68529,-61.65229 8.692257,-61.65274 8.692484,-61.66696 8.700033,-61.67293 8.703267,-61.68117 8.707694,-61.69384 8.714316,-61.69542 8.715144,-61.70964 8.722702,-61.71437 8.725309,-61.72383 8.730533,-61.73432 8.736211,-61.73804 8.738198,-61.75226 8.7458,-61.75472 8.74718,-61.76644 8.753654,-61.77439 8.758038,-61.78063 8.761465,-61.79445 8.768953,-61.79484 8.769164,-61.80901 8.777071,-61.81376 8.779755,-61.82317 8.785094,-61.83304 8.790551,-61.83736 8.792919,-61.85155 8.800729,-61.85273 8.801407,-61.86571 8.808746,-61.87173 8.812159,-61.87987 8.816762,-61.89117 8.822974,-61.89407 8.824567,-61.90826 8.832401,-61.91071 8.833805,-61.92243 8.840391,-61.9299 8.844581,-61.9366 8.848328,-61.9496 8.855433,-61.95081 8.856088,-61.96499 8.863957,-61.96915 8.86626,-61.97918 8.871832,-61.98875 8.877094,-61.99338 8.879601,-62.00761 8.887224,-62.00907 8.888036,-62.02182 8.894998,-62.02905 8.898924,-62.03603 8.902689,-62.05005 8.909962,-62.05029 8.910091,-62.06453 8.917704,-62.07048 8.920915,-62.07875 8.925356,-62.09206 8.932038,-62.09305 8.932536,-62.10732 8.939863,-62.11376 8.943178,-62.12159 8.94722,-62.13592 8.954215,-62.1364 8.954457,-62.15022 8.961379,-62.15909 8.96574,-62.16455 8.96839,-62.1789 8.975253,-62.18281 8.977177,-62.19324 8.98214,-62.20764 8.98867,-62.20798 8.988827,-62.22201 8.995404,-62.23342 9.000515,-62.23643 9.001826,-62.25085 9.008245,-62.26033 9.01242,-62.26528 9.014573,-62.27974 9.020734,-62.28868 9.024536,-62.29421 9.026849,-62.3087 9.032805,-62.31877 9.036909,-62.3232 9.038696,-62.33772 9.044497,-62.35092 9.049583,-62.35226 9.050092,-62.3668 9.055778,-62.38138 9.061171,-62.38496 9.062535,-62.39595 9.066626,-62.41054 9.071913,-62.42165 9.075877,-62.42515 9.077108,-62.43976 9.082321,-62.4544 9.087303,-62.46095 9.089601,-62.46903 9.092345,-62.4837 9.097211,-62.49837 9.101977,-62.5042 9.103905,-62.51305 9.106755,-62.52774 9.11144,-62.54244 9.116015,-62.55107 9.118738,-62.55715 9.120593,-62.57186 9.125143,-62.5866 9.12951,-62.60134 9.13385,-62.6027 9.134266,-62.61607 9.138303,-62.63081 9.142658,-62.64559 9.146787,-62.65738 9.150236,-62.66034 9.151083,-62.67508 9.1554,-62.68985 9.159601,-62.70463 9.163695,-62.71505 9.166639,-62.71941 9.167835,-62.73417 9.172075,-62.74895 9.176171,-62.76375 9.18018,-62.77516 9.183388,-62.77852 9.184314,-62.7933 9.18848,-62.80808 9.192556,-62.82288 9.196537,-62.836 9.200234,-62.83766 9.200696,-62.85243 9.204911,-62.86721 9.209034,-62.88201 9.213008,-62.89616 9.216968,-62.89679 9.217144,-62.91154 9.221455,-62.92631 9.225656,-62.94111 9.2297,-62.95345 9.233272,-62.95587 9.233962,-62.97061 9.238331,-62.98538 9.242572,-63.00014 9.246852,-63.00793 9.249151,-63.01489 9.251149,-63.02964 9.255538,-63.04439 9.259863,-63.05913 9.264312,-63.0605 9.264743,-63.07385 9.268831,-63.08858 9.273324,-63.1033 9.277867,-63.10941 9.279791,-63.11802 9.282416,-63.13273 9.287043,-63.14745 9.291602,-63.15654 9.294572,-63.16214 9.296362,-63.17684 9.301113,-63.19154 9.305801,-63.20073 9.308917,-63.20621 9.310728,-63.22088 9.315602,-63.23556 9.32047,-63.24252 9.322906,-63.25021 9.325509,-63.26486 9.330543,-63.27952 9.335516,-63.28258 9.336637,-63.29414 9.340751,-63.30879 9.345801,-63.32073 9.350086,-63.32342 9.351025,-63.33803 9.356325,-63.35264 9.361644,-63.35683 9.363232,-63.36724 9.367056,-63.38185 9.372398,-63.39172 9.376198,-63.39643 9.377946,-63.41101 9.383481,-63.4256 9.388971,-63.42577 9.389038,-63.44015 9.394689,-63.45471 9.400371,-63.45759 9.401552,-63.46925 9.406195,-63.48379 9.411991,-63.48841 9.413916,-63.49831 9.41794,-63.51286 9.42373,-63.51856 9.42618,-63.52735 9.42987,-63.54188 9.435778,-63.54756 9.438275,-63.55636 9.442068,-63.57086 9.448139,-63.57554 9.45022,-63.58533 9.45446,-63.59981 9.460716,-63.60279 9.462057,-63.61427 9.467086,-63.62873 9.47348,-63.62943 9.473802,-63.64316 9.480068,-63.65492 9.48538,-63.6576 9.486572,-63.67203 9.493176,-63.6798 9.496868,-63.68644 9.499925,-63.70085 9.506698,-63.70415 9.508277,-63.71525 9.513514,-63.72796 9.519605,-63.72964 9.520394,-63.74402 9.527342,-63.75079 9.530792,-63.75836 9.534523,-63.77274 9.541507,-63.77367 9.541982,-63.78707 9.548808,-63.79536 9.553001,-63.80142 9.556009,-63.81575 9.563295,-63.81715 9.564031,-63.83005 9.570831,-63.83765 9.574875,-63.84435 9.578359,-63.85816 9.585719,-63.85863 9.585973,-63.87291 9.593655,-63.87799 9.596464,-63.88717 9.601486,-63.89757 9.607171,-63.90143 9.609239,-63.91569 9.617038,-63.91721 9.617886,-63.92993 9.625015,-63.936 9.628477,-63.94415 9.633087,-63.95447 9.639021,-63.95837 9.641233,-63.97259 9.64932,-63.97303 9.649577,-63.98678 9.65757,-63.99082 9.660021,-64.00093 9.666158,-64.00796 9.670372,-64.0151 9.674615,-64.02515 9.680728,-64.02925 9.683219,-64.04222 9.691066,-64.0434 9.691781,-64.05754 9.700479,-64.05895 9.701355,-64.07166 9.709306,-64.07515 9.711566,-64.08574 9.718353,-64.09098 9.721724,-64.09982 9.727477,-64.1065 9.731836,-64.11388 9.736659,-64.1218 9.741916,-64.12793 9.745953,-64.13703 9.751986,-64.14198 9.75527,-64.152 9.762018,-64.15601 9.764757,-64.16645 9.771974,-64.17001 9.774424,-64.18087 9.781926,-64.184 9.784119,-64.19493 9.791825,-64.19797 9.793979,-64.20878 9.801693,-64.21193 9.803951,-64.2223 9.811514,-64.22586 9.81411,-64.23582 9.821334,-64.23979 9.82428,-64.24886 9.831085,-64.25367 9.834726,-64.26173 9.840811,-64.26756 9.84523,-64.27455 9.850529,-64.28141 9.855888,-64.28697 9.86019,-64.29526 9.866617,-64.2994 9.869852,-64.30908 9.877549,-64.31154 9.879472,-64.32289 9.888574,-64.32349 9.889065,-64.33499 9.898592,-64.33665 9.899977,-64.34649 9.90812,-64.35039 9.911459,-64.35765 9.917599,-64.36412 9.92306,-64.36883 9.92708,-64.37781 9.93489,-64.37971 9.936518,-64.39048 9.94594,-64.39149 9.946851,-64.40087 9.955307,-64.40511 9.959195,-64.41121 9.964667,-64.41873 9.971496,-64.42154 9.974026,-64.43141 9.983318,-64.43231 9.984178,-64.44103 9.992575,-64.44583 9.997226,-64.45074 10.00184,-64.45937 10.01015,-64.46035 10.0111,-64.46952 10.02029,-64.47282 10.02367,-64.47852 10.02946,-64.48627 10.03726,-64.48765 10.03864,-64.49632 10.04776,-64.49963 10.05139,-64.50479 10.05685,-64.51301 10.06547,-64.5135 10.06598,-64.52155 10.07501,-64.52628 10.08025,-64.52987 10.08408,-64.53768 10.09308,-64.53952 10.09529,-64.54538 10.10206,-64.55274 10.11049,-64.55324 10.11106,-64.56054 10.11998,-64.56584 10.12647,-64.56791 10.12892,-64.57498 10.13781,-64.5789 10.14274,-64.58219 10.14672,-64.58887 10.15556,-64.59188 10.15957,-64.59568 10.16441,-64.602 10.17319,-64.60477 10.17703,-64.60859 10.18202,-64.61467 10.19077,-64.61759 10.19498,-64.62091 10.19954,-64.62659 10.20823,-64.63029 10.2138,-64.63247 10.21695,-64.638 10.22563,-64.6429 10.23321,-64.64365 10.23431,-64.64869 10.24292,-64.65392 10.25155,-64.65532 10.25399,-64.65907 10.26016,-64.66367 10.2687,-64.66761 10.27563,-64.6686 10.27729,-64.67296 10.2858,-64.67743 10.29432,-64.67966 10.2989,-64.6817 10.30281,-64.68575 10.31127,-64.68969 10.31972,-64.69148 10.3238,-64.69352 10.32815,-64.69708 10.33654,-64.70046 10.34491,-64.70297 10.351,-64.70398 10.3533,-64.70694 10.36161,-64.70995 10.36992,-64.71297 10.37824,-64.71397 10.38155,-64.71559 10.3865,-64.71798 10.39473,-64.72045 10.40297,-64.72271 10.41118,-64.72426 10.41703,-64.72493 10.41938,-64.72683 10.42754,-64.72828 10.43564,-64.72991 10.44376,-64.73126 10.45184,-64.73266 10.45993,-64.73304 10.46291))"
poly1 <- st_sf(st_as_sfc(wkt))

我用它来提取相关的线串。

box <- poly1 %>% st_bbox %>% st_as_sfc

sa_coast <- cl10[st_intersects(box,cl10,sparse=FALSE),] %>% 
  mutate(len=st_length(geometry)) %>%
  filter(len==max(len))

在这里,我想使用sa_coast剪辑poly1。但是我不知道如何做到这一点。这是海岸和山脉的样子。地图的北部是海洋,南部是陆地。

ggplot() +
  geom_sf(data=poly1,fill=NA,color='red') +
  geom_sf(data=sa_coast) +
  xlim(st_bbox(poly1)['xmin'],st_bbox(poly1)['xmax']) +
  ylim(st_bbox(poly1)['ymin'],st_bbox(poly1)['ymax']) +
  theme_classic()

Coast and range

我认为st_intersection()不起作用,因为它返回与poly1相交的多行字符串

我想要的是一个多边形,其中的水(图的顶部区域)被裁剪掉了。如下所示,st_intersection()返回的几何为蓝色。

intr <- st_intersection(poly1,sa_coast)

ggplot() +
  geom_sf(data=poly1,fill=NA,color='red') +
  geom_sf(data=sa_coast) + #,mapping=aes(color=rowid)
  geom_sf(data=intr,color='blue') +
  xlim(st_bbox(polys)['xmin'],st_bbox(polys)['xmax']) +
  ylim(st_bbox(polys)['ymin'],st_bbox(polys)['ymax']) +
  theme_classic()

coast and range 2

2 个答案:

答案 0 :(得分:1)

这是我终于想出的解决方案。感谢@JindaLacko,他给了我在线串上使用st_polygonize的想法。但是,我的线串没有关闭,因此st_polygonize无法正常工作。诀窍是使用多边形的边界框裁剪线串,然后将边界框的最小角用作线串上的一个点,然后使用其第一点关闭线串。然后,您可以将其变成多边形。

将海岸线剪切为多边形边界框的大小。

sa_clip <- st_intersection(st_as_sfc(st_bbox(poly1)),sa_coast)
ggplot() +
  geom_sf(data=st_as_sfc(st_bbox(poly1)),fill=NA) +
  geom_sf(data=sa_clip) +
  theme_classic()

获取边界框的最小角

corner <- st_bbox(poly1)[c('xmin','ymin')] %>% st_point %>% st_sfc(crs=4326)

将线串放到点上,追加角,关闭线串,变成多边形。

pts <- sa_clip %>% st_geometry %>% st_cast("POINT")
sa_poly <- c(pts,corner,pts[1]) %>% st_combine %>% st_cast('LINESTRING') %>% st_polygonize

现在,您可以裁剪多边形。

clipped <- st_intersection(sa_poly,poly1)

ggplot() +
  geom_sf(data=sa_poly,fill='red',alpha=.2) +
  geom_sf(data=poly1,fill='blue',alpha=.2) +
  geom_sf(data=clipped,fill='purple',alpha=.2) +
  theme_classic()

enter image description here

答案 1 :(得分:0)

要剪切线串和多边形,请使用sf::st_intersection()

请考虑RStudio社区站点上的示例,在该示例中,我用它来确定北卡罗来纳州(一个受欢迎的数据集)随机县的多边形与第36个平行线的交点。

https://community.rstudio.com/t/how-to-change-color-of-polyline-when-it-is-passing-a-polygon-in-leaflet-package-using-r/37033/3?u=jlacko

编辑:线串和多边形的交集将成为线串。

如果所需的输出是多边形,请考虑在您的线串上调用sf::st_polygonize()。它将变成一个多边形,与另一个多边形相交时将返回一个多边形。