使用 R 将 Web 要素服务地理标记语言数据转换为形状
Converting Web Feature Service Geographical Markup Language data into a shape with R
我正在尝试使用 R 将 XML/GML 中的 Web 要素服务图层转换为 shapefile,但我还不太了解,希望能提供任何帮助。
这是我到目前为止使用 XML 库的工作流程示例(仅从此连接输出其中一层)
library(XML)
library(RCurl)
site <- 'http://sdi.fish.govt.nz/sdi/mapserver.wfs?SERVICE=WFS&REQUEST=GetFeature&TYPENAME=Annual%20distribution%20of%20Albacore%20tuna&VERSION=1.1.0'
albacore <- getURL(site)
albacore_t <- xmlTreeParse(albacore, asText = TRUE)
xmlRoot(albacore_t)
#<?xml version="1.0"?>
#<wfs:FeatureCollection xmlns:gml="http://www.opengis.net/gml" xmlns:fish="http://www.fish.govt.nz/fish" xmlns:gmlsf="http://www.opengis.net/gmlsf" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc" xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:wfs="http://www.opengis.net/wfs" d1p1:schemaLocation="http://www.fish.govt.nz/fish http://sdi.fish.govt.nz/sdi/mapserver.wfs?SERVICE=WFS&REQUEST=DescribeFeatureType&TYPENAME=Annual distribution of Albacore tuna&VERSION=1.1.0; http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
#<gml:featureMember>
#<fish:FD0005_2 gml:id="ID00000">
#<fish:FeatureKey>3986</fish:FeatureKey>
#<fish:LayerKey>6</fish:LayerKey>
#<fish:FeatureGuid>41eb2b37-9e56-4cfa-8a95-7f32f1196de1</fish:FeatureGuid>
#<fish:FeatureType>NOTEXIST</fish:FeatureType>
#<fish:SpeciesCode>ALB</fish:SpeciesCode>
#<fish:GeneralisationYn>Y</fish:GeneralisationYn>
#<fish:Metadata><p1:FD0005_2 xmlns:p1="http://www.safe.com/gml/fme" xmlns:gml="http://www.opengis.net/gml" gml:id="id41eb2b37-9e56-4cfa-8a95-7f32f1196de1"><p1:MFish_ID>1</p1:MFish_ID><p1:Layer_ID>FD0005_1</p1:Layer_ID><p1:Basket_title>Fish distribution</p1:Basket_title><p1:Species_common_name>Albacore Tuna</p1:Species_common_name><p1:Species_scientific_name>Thunnus alalunga (Bonaterre, 1788)</p1:Species_scientific_name><p1:Species_code>ALB</p1:Species_code><p1:Species_maori_name>Unknown</p1:Species_maori_name><p1:Species_group>Albacore Tuna</p1:Species_group><p1:Distribution_class>Not Exist - The species is known not to exist</p1:Distribution_class><p1:Temporal_extent>Annual</p1:Temporal_extent><p1:Object_security>None</p1:Object_security><p1:Object_name /><p1:Object_area>3261385 km2</p1:Object_area><p1:Distribution_class_area>3261385 km2</p1:Distribution_class_area><p1:Positional_accuracy>100 km</p1:Positional_accuracy><p1:Accuracy_explanation>The mapped object is a scientific interpretation of data and is considered accurate to ± 15%</p1:Accuracy_explanation><p1:Habitat_type>Pelagic</p1:Habitat_type><p1:Species_depth_minimum>0 m</p1:Species_depth_minimum><p1:Species_depth_maximum>380 m</p1:Species_depth_maximum><p1:Management>Ministry of Fisheries</p1:Management><p1:Scientific_contact>General Manager, Biodiversity, Biosecurity and Information Systems, NIWA, Private Bag 14901, Wellington. 04 386 0300</p1:Scientific_contact><p1:Object_references /><p1:Endangered_status>Not listed</p1:Endangered_status><p1:Keywords>Not exist</p1:Keywords><p1:Alert>N</p1:Alert><p1:Alert_warning>None</p1:Alert_warning></p1:FD0005_2></fish:Metadata>
#<fish:LayerTitle>Annual distribution of Albacore tuna NOTEXIST</fish:LayerTitle>
#<fish:LayerGroup>FD3776</fish:LayerGroup>
#<fish:LayerName>FD0005_2</fish:LayerName>
#<fish:LayerzOrder>300002</fish:LayerzOrder>
#<fish:FishGeometry>
# <gml:Polygon xmlns="http://www.opengis.net/gml" xmlns:gml="http://www.opengis.net/gml">
# <gml:exterior>
# <gml:LinearRing>
# <gml:posList>157 -43.924285 157.633016 -43.933348 157.662723 -43.94083 157.69243 -43.94831 157.708918 -43.953266 157.725406 -43.958222 157.741942 -43.960776 157.75843 -43.965731 157.778235 -43.970716 157.794723 -43.97567 157.811209 -43.980623 157.840868 -43.990499 157.860673 -43.995482 157.877159 -44.000434 157.893647 -44.005385 157.910135 -44.010337 157.943109 -44.020238 157.976084 -44.030137 158.009109 -44.037637 158.042133 -44.045137 158.07184 -44.052604 158.09828 -44.057643 158.127986 -44.065109 158.157695 -44.072575 158.190719 -44.08007 158.223743 -44.087563 158.260085 -44.095087 158.299793 -44.100246 158.336136 -44.107767 158.375845 -44.112925 158.412236 -44.118051 158.44526 -44.12554 158.481652 -44.130665 158.514726 -44.135759 158.5478 -44.140852 158.580874 -44.145946 158.610681 -44.148614 158.643754 -44.153707 158.676828 -44.158799 158.706635 -44.161467 158.736392 -44.166527 158.769516 -44.169226 158.805907 -44.174347 158.842299 -44.179468 158.882007 -44.184619 158.921716 -44.18977 158.961475 -44.192529 159.004451 -44.2001 159.047477 -44.20528 159.090503 -44.210459 159.136847 -44.215668 159.179823 -44.223237 159.229434 -44.230866 159.279046 -44.238493 159.325289 -44.248478 159.374901 -44.256103 159.424463 -44.266117 159.470756 -44.273709 159.517001 -44.283687 159.566562 -44.293696 159.589684 -44.298684 159.616124 -44.303702 159.639246 -44.308689 159.662368 -44.313675 159.685491 -44.318662 159.708563 -44.326034 159.761441 -44.336065 159.811003 -44.346064 159.860565 -44.356061 159.903442 -44.36838 159.946368 -44.378311 159.985978 -44.388212 160.025539 -44.400493 160.06183 -44.410358 160.10144 -44.420253 160.137732 -44.430115 160.174025 -44.439976 160.206999 -44.449805 160.239974 -44.459631 160.276316 -44.467107 160.312609 -44.476962 160.3489 -44.486814 160.385193 -44.496666 160.418217 -44.504106 160.451242 -44.511546 160.484217 -44.521362 160.520509 -44.531207 160.553533 -44.538643 160.589826 -44.548486 160.62285 -44.55592 160.659143 -44.565759 160.692117 -44.575566 160.728459 -44.583027 160.768069 -44.592892 160.801043 -44.602695 160.837386 -44.610152 160.873677 -44.619982 160.90997 -44.629811 160.946312 -44.637264 160.985922 -44.64712 161.022263 -44.654572 161.055237 -44.664364 161.088263 -44.671783 161.11797 -44.67917 161.150944 -44.688958 161.187286 -44.696404 161.220261 -44.706189 161.240066 -44.711112 161.256553 -44.716003 161.27304 -44.720894 161.302747 -44.728274999999996 161.319235 -44.733166 161.335723 -44.738055 161.352211 -44.742944 161.368697 -44.747833 161.385235 -44.750353 161.401723 -44.755241 161.418209 -44.760129 161.444599 -44.767475 161.461087 -44.772362 161.487476 -44.779706 161.513817 -44.789416 161.543524 -44.796789 161.569864 -44.806496 161.586352 -44.811379 161.616059 -44.818749 161.645717 -44.828483 161.672107 -44.83582 161.701764 -44.845551 161.728153 -44.852886 161.754543 -44.86022 161.780933 -44.867553 161.807274 -44.877248 161.833663 -44.88458 161.860053 -44.891909 161.883075 -44.901571 161.906149 -44.908868 161.932489 -44.918556 161.958828 -44.928243 161.985119 -44.940288 162.014777 -44.950001 162.044335 -44.964432 162.060823 -44.969302 162.07726 -44.97653 162.093698 -44.983758 162.110136 -44.990984 162.129891 -44.998241 162.146329 -45.005466 162.162817 -45.010331 162.179255 -45.017555 162.195692 -45.024777 162.21213 -45.031999 162.228617 -45.036862 162.245055 -45.044082 162.261493 -45.051302 162.27798 -45.056163 162.294418 -45.063381 162.310856 -45.070598 162.330661 -45.075488 162.347099 -45.082703 162.376707 -45.094747 162.393194 -45.099605 162.409632 -45.106817 162.43924 -45.118855 162.455728 -45.123711 162.472165 -45.13092 162.488652 -45.135776 162.50509 -45.142984 162.521578 -45.147838 162.538015 -45.155044 162.554503 -45.159898 162.584111 -45.171924 162.600549 -45.179127 162.617036 -45.183979 162.633474 -45.191179 162.649961 -45.19603 162.67952 -45.210398 162.696008 -45.215246 162.712445 -45.222444 162.728883 -45.22964 162.74537 -45.234488 162.774928 -45.248846 162.791366 -45.256039 162.807804 -45.263231 162.824242 -45.270422 162.840679 -45.277612 162.857117 -45.284802 162.893212 -45.303898 162.926037 -45.320613 162.955596 -45.33495 162.988421 -45.351656 163.021247 -45.368358 163.050757 -45.385024 163.083583 -45.401716 163.113141 -45.416032 163.142649 -45.432684 163.175475 -45.449361 163.204984 -45.466004 163.234492 -45.482641 163.264002 -45.499273 163.29351 -45.515901 163.322969 -45.534859 163.352477 -45.551476 163.368915 -45.55863 163.388621 -45.568148 163.405009 -45.577634 163.421447 -45.584785 163.450956 -45.601387 163.477147 -45.617954 163.493535 -45.627432 163.523044 -45.644021 163.552553 -45.660605 163.582011 -45.679515 163.61152 -45.696089 163.637662 -45.714956 163.6541 -45.722089 163.680241 -45.740948 163.706433 -45.757474 163.732575 -45.77632 163.758716 -45.79516 163.784908 -45.81167 163.81105 -45.830497 163.837241 -45.846997 163.863382 -45.865813 163.886256 -45.882271 163.90913 -45.898726 163.932004 -45.915174 163.958147 -45.933967 163.98102 -45.950405 164.003844 -45.969157 164.02667 -45.987901 164.049494 -46.00664 164.059197 -46.018307 164.081972 -46.03935 164.094993 -46.05104 164.104698 -46.062698 164.117718 -46.074383 164.13074 -46.086066 164.140444 -46.097716 164.153416 -46.111705 164.166436 -46.12338 164.179408 -46.137362 164.192429 -46.149032 164.205401 -46.163008 164.218373 -46.17698 164.231344 -46.19095 164.244316 -46.204915 164.254019 -46.21654 164.266991 -46.230499 164.280013 -46.242148 164.289667 -46.256071 164.302688 -46.267715 164.312392 -46.279326 164.322095 -46.290936 164.335117 -46.302573 164.344821 -46.314177 164.354525 -46.325779 164.364229 -46.337378 164.377249 -46.349005 164.386954 -46.3606 164.406411 -46.381481 164.412798 -46.393039 164.422502 -46.404624 164.44196 -46.425489 164.458099 -46.446316 164.467804 -46.45789 164.477507 -46.469461 164.483893 -46.481001 164.493598 -46.492567 164.503251 -46.506425 164.522561 -46.534132 164.541919 -46.559532 164.561277 -46.58492 164.583903 -46.612615 164.606578 -46.638008 164.629253 -46.663388 164.648612 -46.688728 164.674506 -46.718684 164.687478 -46.732515 164.700448 -46.746341 164.71342 -46.760164 164.723075 -46.773953 164.736096 -46.785486 164.74575 -46.79927 164.755454 -46.810767 164.768426 -46.824574 164.778129 -46.836066 164.787834 -46.847556 164.797487 -46.861324 164.807192 -46.872808 164.820213 -46.884319 164.829916 -46.8958 164.839621 -46.907277 164.852493 -46.925612 164.862196 -46.937083 164.87507 -46.955408 164.891259 -46.973756 164.904131 -46.992068 164.917003 -47.010373 164.923391 -47.021797 164.936263 -47.040093 164.949135 -47.058382 164.961957 -47.078936 164.974831 -47.097212 164.987653 -47.11775 165.000525 -47.136012 165.016716 -47.154297 165.029588 -47.172548 165.039192 -47.188497 165.048797 -47.204441 165.058451 -47.218116 165.064738 -47.234022 165.071076 -47.24766 165.08068 -47.263587 165.086967 -47.27948 165.096572 -47.295396 165.102809 -47.313539 165.112364 -47.331705 165.12192 -47.349865 165.128108 -47.370247 165.137613 -47.39065 165.147169 -47.40879 165.150238 -47.420098 165.159743 -47.440481 165.162813 -47.451783 165.172318 -47.472155 165.181822 -47.492518 165.18821 -47.503837 165.197715 -47.524189 165.20722 -47.544532 165.213607 -47.55584 165.223112 -47.576171 165.226182 -47.587443 165.235687 -47.607761 165.242073 -47.619056 165.245143 -47.630319 165.251529 -47.641608 165.254598 -47.652866 165.260936 -47.666396 165.264005 -47.677649 165.270391 -47.688928 165.273461 -47.700176 165.279797 -47.713693 165.282817 -47.727178 165.289154 -47.740688 165.292173 -47.754166 165.298461 -47.76991 165.304797 -47.783409 165.311085 -47.799143 165.317372 -47.814874 165.320342 -47.83057 165.332917 -47.862007 165.345541 -47.891188 165.354898 -47.91809 165.364304 -47.942745 165.370443 -47.965128 165.37663 -47.985271 165.379551 -48.003146 165.382471 -48.021015 165.385391 -48.038877 165.391629 -48.056763 165.394549 -48.074612 165.400788 -48.092485 165.403757 -48.108097 165.406727 -48.123704 165.409648 -48.141531 165.412618 -48.157128 165.415588 -48.172721 165.418607 -48.186085 165.421577 -48.201668 165.42118 -48.21944 165.42415 -48.235013 165.423803 -48.250552 165.426774 -48.266116 165.429694 -48.283894 165.432663 -48.299447 165.435583 -48.317212 165.435186 -48.334943 165.43474 -48.354883 165.437611 -48.374843 165.437114 -48.39698 165.436668 -48.416896 165.439489 -48.439043 165.435676 -48.461124 165.435179 -48.483223 165.434633 -48.507522 165.430721 -48.533987 165.430125 -48.560468 165.426163 -48.58911 165.425468 -48.619968 165.421406 -48.652981 165.417345 -48.685973 165.416601 -48.71897 165.412489 -48.754115 165.408378 -48.789236 165.404267 -48.824332 165.400106 -48.861596 165.395994 -48.896641 165.391883 -48.931662 165.390989 -48.971062 165.387275 -48.988535 165.386829 -49.008217 165.386481 -49.023518 165.382767 -49.040973 165.38237 -49.058449 165.381973 -49.07592 165.378259 -49.093356 165.377912 -49.108632 165.377515 -49.126084 165.377168 -49.14135 165.376771 -49.15879 165.373106 -49.174018 165.372709 -49.191448 165.372361 -49.206694 165.372014 -49.221934 165.3684 -49.234966 165.368051 -49.250198 165.367704 -49.265425 165.36740699999999 -49.278474 165.367059 -49.293692 165.366712 -49.308906 165.366415 -49.321942 165.366066 -49.337148 165.365769 -49.350177 165.365471 -49.363203 165.365174 -49.376225 165.364876 -49.389244 165.364578 -49.402259 165.361013 -49.413074 165.360716 -49.426084 165.360467 -49.436921 165.360169 -49.449924 165.359922 -49.460757 165.359623 -49.473753 165.359375 -49.48458 165.359078 -49.497571 165.358829 -49.508393 165.358532 -49.521376 165.358284 -49.532193 165.357837 -49.551657 165.357588 -49.562468 165.357191 -49.579759 165.356944 -49.590563 165.356547 -49.607845 165.352833 -49.625092 165.352436 -49.642361 165.348722 -49.659596 165.348325 -49.676853 165.347928 -49.694103 165.344262 -49.709165 165.343915 -49.724249 165.340251 -49.739302 165.339903 -49.754376 165.339556 -49.769447 165.335841 -49.786637 165.335494 -49.801697 165.335147 -49.816752 165.33475 -49.833953 165.334402 -49.848999 165.334105 -49.861891 165.333758 -49.876928 165.333361 -49.894107 165.333012 -49.909134 165.332615 -49.9263 165.335537 -49.943489 165.33514 -49.960645 165.334743 -49.977794 165.334495 -49.988509 165.337415 -50.005676 165.337167 -50.016384 165.339888 -50.042103 165.339491 -50.059223 165.339144 -50.074198 165.342115 -50.089196 165.345084 -50.104188 165.344736 -50.119149 165.347657 -50.136268 165.350627 -50.151247 165.35023 -50.168327 165.3532 -50.183295 165.356121 -50.200392 165.355724 -50.217455 165.358644 -50.234539 165.361564 -50.251617 165.361167 -50.268661 165.36077 -50.2857 165.360373 -50.302732 165.363244 -50.321914 165.366164 -50.338961 165.365767 -50.355974 165.368687 -50.373008 165.368291 -50.390009 165.371212 -50.407031 165.370765 -50.426143 165.373685 -50.443152 165.376555 -50.462276 165.379426 -50.481393 165.382297 -50.500502 165.385218 -50.517483 165.388088 -50.536577 165.390959 -50.555664 165.397197 -50.572653 165.400166 -50.587493 165.403137 -50.602329 165.406107 -50.617159 165.409077 -50.631986 165.412047 -50.646807 165.415016 -50.661624 165.417937 -50.678547 165.424125 -50.697603 165.426996 -50.716624 165.429866 -50.735637 165.432738 -50.754642 165.438925 -50.773667 165.445113 -50.792683 165.447985 -50.811665 165.45749 -50.830693 165.463677 -50.849687 165.469866 -50.868672 165.476104 -50.885548 165.485609 -50.904546 165.495163 -50.921435 165.501401 -50.938291 165.510957 -50.955169 165.520562 -50.969941 165.530165 -50.984709 165.53982 -50.997375 165.549524 -51.007941 165.555911 -51.018476 165.575468 -51.03331 165.594974 -51.050233 165.617798 -51.067176 165.647258 -51.084167 165.663646 -51.092674 165.680084 -51.099086 165.703156 -51.105551 165.722911 -51.111988 165.746033 -51.11636 165.769106 -51.122822 165.792278 -51.125101 165.8154 -51.129472 165.841889 -51.131778 165.868428 -51.131991 165.894966 -51.132206 165.911553 -51.13234 165.938092 -51.132554 165.954679 -51.132688 165.984584 -51.130838 166.001171 -51.130972 166.031027 -51.131213 166.047614 -51.131347 166.080886 -51.127432 166.117426 -51.125636 166.150649 -51.123812 166.180604 -51.11987 166.213827 -51.118047 166.2471 -51.114131 166.277055 -51.110188 166.310328 -51.106271 166.346918 -51.102382 166.383508 -51.098491 166.41678 -51.094574 166.45342 -51.08859 166.486743 -51.082579 166.516748 -51.07654 166.550069 -51.070526 166.580125 -51.062391 166.610179 -51.054255 166.640233 -51.046117 166.66697 -51.037951 166.693707 -51.029783 166.717128 -51.021588 166.740597 -51.011293 166.764067 -51.000997 166.784219 -50.990672 166.804421 -50.978246 166.824573 -50.967916 166.841456 -50.955457 166.861658 -50.943021 166.878593 -50.928456 166.896648 -50.913652 167.275366 -50.793788 167.636773 -50.6073 168.063648 -50.423553 168.685367 -50.154646 168.849714 -50.079074 169.01699 -49.993825 169.538563 -49.727041 170.127814 -49.455712 171.012056 -49.076589 171.756449 -48.801285 172.286423 -48.619422 172.695583 -48.497199 173.303232 -48.298451 173.659814 -48.181457 174.480379 -47.932891 174.872698 -47.83127 175.537502 -47.692526 175.956819 -47.596965 176.603641 -47.430025 176.684586 -47.409784 178.33032 -47.047093 178.64661 -46.983468 180.682187 -46.504255 181.149527 -46.372492 182.389396 -45.970896 182.886735 -45.783124 184.197319 -45.295544 184.695737 -45.089964 185.289578 -44.859361 185.625882 -44.750535 185.957221 -44.657345 186.241194 -44.585981 186.665232 -44.485559 186.717083 -44.474465 186.767091 -44.463023 186.820416 -44.451609 186.873791 -44.437812 186.927117 -44.426393 186.980492 -44.412589 187.037135 -44.401196 187.09051 -44.387387 187.147202 -44.373605 187.203894 -44.359819 187.257221 -44.348385 187.310595 -44.334563 187.36397 -44.320738 187.417296 -44.309296 187.470671 -44.295465 187.527364 -44.281661 187.580739 -44.267824 187.634064 -44.256372 187.684122 -44.242497 187.737498 -44.22865 187.760917 -44.219305 187.787605 -44.212379 187.814292 -44.205452 187.84098 -44.198525 187.864351 -44.191566 187.88772 -44.184606 187.914408 -44.177676 187.937778 -44.170715 187.961148 -44.163753 187.984518 -44.15679 188.007889 -44.149826 188.031259 -44.142861 188.054579 -44.138289 188.10132 -44.124356 188.151378 -44.11045 188.201485 -44.094146 188.248226 -44.080203 188.298333 -44.063891 188.348441 -44.047573 188.401815 -44.03368 188.45519 -44.019784 188.505249 -44.005854 188.558674 -43.989551 188.608731 -43.975614 188.662106 -43.961704 188.715481 -43.947791 188.768856 -43.933874 188.825549 -43.919985 188.878924 -43.906062 188.935616 -43.892166 188.992309 -43.878267 189.045734 -43.86193 189.102426 -43.848024 189.155851 -43.831678 189.205908 -43.817703 189.259333 -43.801349 189.306073 -43.787336 189.352813 -43.77332 189.396238 -43.75927 189.436392 -43.742776 189.459763 -43.735763 189.479865 -43.726308 189.503236 -43.719293 189.519971 -43.712216 189.540024 -43.705168 189.560028 -43.700532 189.58008 -43.693483 189.600133 -43.686433 189.620136 -43.681795 189.640139 -43.677156 189.656875 -43.670074 189.676878 -43.665434 189.696881 -43.660794 189.716935 -43.653741 189.736938 -43.649099 189.753673 -43.642014 189.773677 -43.637372 189.793729 -43.630315 189.813732 -43.625673 189.833786 -43.618615 189.853838 -43.611557 189.873842 -43.606913 189.893895 -43.599853 189.913947 -43.592792 189.933951 -43.588147 189.950686 -43.581053 189.970739 -43.57399 189.990743 -43.569344 190.007478 -43.562248 190.027481 -43.5576 190.047485 -43.552952 190.06417 -43.548272 190.084173 -43.543623 190.10086 -43.538942 190.120912 -43.531874 190.137598 -43.527193 190.157602 -43.522542 190.174288 -43.51786 190.194291 -43.513208 190.210976 -43.508526 190.23093 -43.506293 190.247616 -43.501609 190.26762 -43.496957 190.287623 -43.492303 190.307626 -43.48765 190.327579 -43.485416 190.347583 -43.480762 190.367586 -43.476107 190.38759 -43.471453 190.410911 -43.466829 190.430864 -43.464595 190.454184 -43.45997 190.477505 -43.455344 190.500825 -43.45072 190.524146 -43.446094 190.547467 -43.441467 190.570788 -43.436842 190.597425 -43.432246 190.620746 -43.427619 190.644066 -43.422991 190.670704 -43.418394 190.694025 -43.413766 190.720663 -43.409169 190.74735 -43.402148 190.770671 -43.397518 190.797359 -43.390496 190.823997 -43.385897 190.850684 -43.378873 190.877322 -43.374273 190.900693 -43.367216 190.927331 -43.362615 190.954018 -43.355589 190.977338 -43.350956 191.004026 -43.343928 191.027347 -43.339294 191.054034 -43.332265 191.080722 -43.325235 191.107409 -43.318204 191.164102 -43.304171 191.220794 -43.290134 191.277437 -43.278523 191.33418 -43.262052 191.390922 -43.245577 191.447614 -43.231526 191.504356 -43.215043 191.561048 -43.200985 191.621107 -43.184524 191.681166 -43.168058 191.737908 -43.151558 191.791333 -43.13502 191.844758 -43.118479 191.90155 -43.099529 191.954974 -43.082977 192.011716 -43.066454 192.06841 -43.052362 192.121835 -43.035798 192.178577 -43.019261 192.235269 -43.005159 192.295328 -42.988644 192.35202 -42.974534 193 -42.963692 193 -58 157 -58 157 -43.924285</gml:posList>
#</gml:LinearRing>
#</gml:exterior>
#</gml:Polygon>
#</fish:FishGeometry>
#</fish:FD0005_2>
#</gml:featureMember>
#<gml:featureMember>
我现在想将此输出转换为形状,我想我应该使用具有 GML 驱动程序的 ogr2ogr
,甚至可能绕过上面的 XML
。非常感谢任何帮助
library(rgdal)
library(gdalUtils)
ogr2ogr()
readOGR()
我认为你很接近...获取 GML 后,我不得不清理前几个 non-standard 个字符:
gml = substr(albacore,4,nchar(albacore))
从那里,将其作为 GML 文件写入磁盘(可能有一个花哨的技巧 textConnection
或类似的东西来避免写入):
write(gml, "/Users/Benjamin/Desktop/test.gml", sep="")
然后,从文件中读取一层:
data = readOGR("/Users/Benjamin/Desktop/test.gml", "FD0002_2")
>>> OGR data source with driver: GML
>>> Source: "/Users/Benjamin/Desktop/test.gml", layer: "FD0002_2"
>>> with 1 features
>>> It has 12 fields
并写入输出 shapefile:
writeOGR(data, "/Users/Benjamin/Desktop/test.shp", "FD0002_2", driver="ESRI Shapefile")
>>> Warning message:
>>> In writeOGR(data, "/Users/Benjamin/Desktop/test.shp", "FD0002_2", :
>>> Field names abbreviated for ESRI Shapefile driver
您可以使用以下方法查找图层名称:
ogrListLayers("/Users/Benjamin/Desktop/test.gml")
我正在尝试使用 R 将 XML/GML 中的 Web 要素服务图层转换为 shapefile,但我还不太了解,希望能提供任何帮助。
这是我到目前为止使用 XML 库的工作流程示例(仅从此连接输出其中一层)
library(XML)
library(RCurl)
site <- 'http://sdi.fish.govt.nz/sdi/mapserver.wfs?SERVICE=WFS&REQUEST=GetFeature&TYPENAME=Annual%20distribution%20of%20Albacore%20tuna&VERSION=1.1.0'
albacore <- getURL(site)
albacore_t <- xmlTreeParse(albacore, asText = TRUE)
xmlRoot(albacore_t)
#<?xml version="1.0"?>
#<wfs:FeatureCollection xmlns:gml="http://www.opengis.net/gml" xmlns:fish="http://www.fish.govt.nz/fish" xmlns:gmlsf="http://www.opengis.net/gmlsf" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc" xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:wfs="http://www.opengis.net/wfs" d1p1:schemaLocation="http://www.fish.govt.nz/fish http://sdi.fish.govt.nz/sdi/mapserver.wfs?SERVICE=WFS&REQUEST=DescribeFeatureType&TYPENAME=Annual distribution of Albacore tuna&VERSION=1.1.0; http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
#<gml:featureMember>
#<fish:FD0005_2 gml:id="ID00000">
#<fish:FeatureKey>3986</fish:FeatureKey>
#<fish:LayerKey>6</fish:LayerKey>
#<fish:FeatureGuid>41eb2b37-9e56-4cfa-8a95-7f32f1196de1</fish:FeatureGuid>
#<fish:FeatureType>NOTEXIST</fish:FeatureType>
#<fish:SpeciesCode>ALB</fish:SpeciesCode>
#<fish:GeneralisationYn>Y</fish:GeneralisationYn>
#<fish:Metadata><p1:FD0005_2 xmlns:p1="http://www.safe.com/gml/fme" xmlns:gml="http://www.opengis.net/gml" gml:id="id41eb2b37-9e56-4cfa-8a95-7f32f1196de1"><p1:MFish_ID>1</p1:MFish_ID><p1:Layer_ID>FD0005_1</p1:Layer_ID><p1:Basket_title>Fish distribution</p1:Basket_title><p1:Species_common_name>Albacore Tuna</p1:Species_common_name><p1:Species_scientific_name>Thunnus alalunga (Bonaterre, 1788)</p1:Species_scientific_name><p1:Species_code>ALB</p1:Species_code><p1:Species_maori_name>Unknown</p1:Species_maori_name><p1:Species_group>Albacore Tuna</p1:Species_group><p1:Distribution_class>Not Exist - The species is known not to exist</p1:Distribution_class><p1:Temporal_extent>Annual</p1:Temporal_extent><p1:Object_security>None</p1:Object_security><p1:Object_name /><p1:Object_area>3261385 km2</p1:Object_area><p1:Distribution_class_area>3261385 km2</p1:Distribution_class_area><p1:Positional_accuracy>100 km</p1:Positional_accuracy><p1:Accuracy_explanation>The mapped object is a scientific interpretation of data and is considered accurate to ± 15%</p1:Accuracy_explanation><p1:Habitat_type>Pelagic</p1:Habitat_type><p1:Species_depth_minimum>0 m</p1:Species_depth_minimum><p1:Species_depth_maximum>380 m</p1:Species_depth_maximum><p1:Management>Ministry of Fisheries</p1:Management><p1:Scientific_contact>General Manager, Biodiversity, Biosecurity and Information Systems, NIWA, Private Bag 14901, Wellington. 04 386 0300</p1:Scientific_contact><p1:Object_references /><p1:Endangered_status>Not listed</p1:Endangered_status><p1:Keywords>Not exist</p1:Keywords><p1:Alert>N</p1:Alert><p1:Alert_warning>None</p1:Alert_warning></p1:FD0005_2></fish:Metadata>
#<fish:LayerTitle>Annual distribution of Albacore tuna NOTEXIST</fish:LayerTitle>
#<fish:LayerGroup>FD3776</fish:LayerGroup>
#<fish:LayerName>FD0005_2</fish:LayerName>
#<fish:LayerzOrder>300002</fish:LayerzOrder>
#<fish:FishGeometry>
# <gml:Polygon xmlns="http://www.opengis.net/gml" xmlns:gml="http://www.opengis.net/gml">
# <gml:exterior>
# <gml:LinearRing>
# <gml:posList>157 -43.924285 157.633016 -43.933348 157.662723 -43.94083 157.69243 -43.94831 157.708918 -43.953266 157.725406 -43.958222 157.741942 -43.960776 157.75843 -43.965731 157.778235 -43.970716 157.794723 -43.97567 157.811209 -43.980623 157.840868 -43.990499 157.860673 -43.995482 157.877159 -44.000434 157.893647 -44.005385 157.910135 -44.010337 157.943109 -44.020238 157.976084 -44.030137 158.009109 -44.037637 158.042133 -44.045137 158.07184 -44.052604 158.09828 -44.057643 158.127986 -44.065109 158.157695 -44.072575 158.190719 -44.08007 158.223743 -44.087563 158.260085 -44.095087 158.299793 -44.100246 158.336136 -44.107767 158.375845 -44.112925 158.412236 -44.118051 158.44526 -44.12554 158.481652 -44.130665 158.514726 -44.135759 158.5478 -44.140852 158.580874 -44.145946 158.610681 -44.148614 158.643754 -44.153707 158.676828 -44.158799 158.706635 -44.161467 158.736392 -44.166527 158.769516 -44.169226 158.805907 -44.174347 158.842299 -44.179468 158.882007 -44.184619 158.921716 -44.18977 158.961475 -44.192529 159.004451 -44.2001 159.047477 -44.20528 159.090503 -44.210459 159.136847 -44.215668 159.179823 -44.223237 159.229434 -44.230866 159.279046 -44.238493 159.325289 -44.248478 159.374901 -44.256103 159.424463 -44.266117 159.470756 -44.273709 159.517001 -44.283687 159.566562 -44.293696 159.589684 -44.298684 159.616124 -44.303702 159.639246 -44.308689 159.662368 -44.313675 159.685491 -44.318662 159.708563 -44.326034 159.761441 -44.336065 159.811003 -44.346064 159.860565 -44.356061 159.903442 -44.36838 159.946368 -44.378311 159.985978 -44.388212 160.025539 -44.400493 160.06183 -44.410358 160.10144 -44.420253 160.137732 -44.430115 160.174025 -44.439976 160.206999 -44.449805 160.239974 -44.459631 160.276316 -44.467107 160.312609 -44.476962 160.3489 -44.486814 160.385193 -44.496666 160.418217 -44.504106 160.451242 -44.511546 160.484217 -44.521362 160.520509 -44.531207 160.553533 -44.538643 160.589826 -44.548486 160.62285 -44.55592 160.659143 -44.565759 160.692117 -44.575566 160.728459 -44.583027 160.768069 -44.592892 160.801043 -44.602695 160.837386 -44.610152 160.873677 -44.619982 160.90997 -44.629811 160.946312 -44.637264 160.985922 -44.64712 161.022263 -44.654572 161.055237 -44.664364 161.088263 -44.671783 161.11797 -44.67917 161.150944 -44.688958 161.187286 -44.696404 161.220261 -44.706189 161.240066 -44.711112 161.256553 -44.716003 161.27304 -44.720894 161.302747 -44.728274999999996 161.319235 -44.733166 161.335723 -44.738055 161.352211 -44.742944 161.368697 -44.747833 161.385235 -44.750353 161.401723 -44.755241 161.418209 -44.760129 161.444599 -44.767475 161.461087 -44.772362 161.487476 -44.779706 161.513817 -44.789416 161.543524 -44.796789 161.569864 -44.806496 161.586352 -44.811379 161.616059 -44.818749 161.645717 -44.828483 161.672107 -44.83582 161.701764 -44.845551 161.728153 -44.852886 161.754543 -44.86022 161.780933 -44.867553 161.807274 -44.877248 161.833663 -44.88458 161.860053 -44.891909 161.883075 -44.901571 161.906149 -44.908868 161.932489 -44.918556 161.958828 -44.928243 161.985119 -44.940288 162.014777 -44.950001 162.044335 -44.964432 162.060823 -44.969302 162.07726 -44.97653 162.093698 -44.983758 162.110136 -44.990984 162.129891 -44.998241 162.146329 -45.005466 162.162817 -45.010331 162.179255 -45.017555 162.195692 -45.024777 162.21213 -45.031999 162.228617 -45.036862 162.245055 -45.044082 162.261493 -45.051302 162.27798 -45.056163 162.294418 -45.063381 162.310856 -45.070598 162.330661 -45.075488 162.347099 -45.082703 162.376707 -45.094747 162.393194 -45.099605 162.409632 -45.106817 162.43924 -45.118855 162.455728 -45.123711 162.472165 -45.13092 162.488652 -45.135776 162.50509 -45.142984 162.521578 -45.147838 162.538015 -45.155044 162.554503 -45.159898 162.584111 -45.171924 162.600549 -45.179127 162.617036 -45.183979 162.633474 -45.191179 162.649961 -45.19603 162.67952 -45.210398 162.696008 -45.215246 162.712445 -45.222444 162.728883 -45.22964 162.74537 -45.234488 162.774928 -45.248846 162.791366 -45.256039 162.807804 -45.263231 162.824242 -45.270422 162.840679 -45.277612 162.857117 -45.284802 162.893212 -45.303898 162.926037 -45.320613 162.955596 -45.33495 162.988421 -45.351656 163.021247 -45.368358 163.050757 -45.385024 163.083583 -45.401716 163.113141 -45.416032 163.142649 -45.432684 163.175475 -45.449361 163.204984 -45.466004 163.234492 -45.482641 163.264002 -45.499273 163.29351 -45.515901 163.322969 -45.534859 163.352477 -45.551476 163.368915 -45.55863 163.388621 -45.568148 163.405009 -45.577634 163.421447 -45.584785 163.450956 -45.601387 163.477147 -45.617954 163.493535 -45.627432 163.523044 -45.644021 163.552553 -45.660605 163.582011 -45.679515 163.61152 -45.696089 163.637662 -45.714956 163.6541 -45.722089 163.680241 -45.740948 163.706433 -45.757474 163.732575 -45.77632 163.758716 -45.79516 163.784908 -45.81167 163.81105 -45.830497 163.837241 -45.846997 163.863382 -45.865813 163.886256 -45.882271 163.90913 -45.898726 163.932004 -45.915174 163.958147 -45.933967 163.98102 -45.950405 164.003844 -45.969157 164.02667 -45.987901 164.049494 -46.00664 164.059197 -46.018307 164.081972 -46.03935 164.094993 -46.05104 164.104698 -46.062698 164.117718 -46.074383 164.13074 -46.086066 164.140444 -46.097716 164.153416 -46.111705 164.166436 -46.12338 164.179408 -46.137362 164.192429 -46.149032 164.205401 -46.163008 164.218373 -46.17698 164.231344 -46.19095 164.244316 -46.204915 164.254019 -46.21654 164.266991 -46.230499 164.280013 -46.242148 164.289667 -46.256071 164.302688 -46.267715 164.312392 -46.279326 164.322095 -46.290936 164.335117 -46.302573 164.344821 -46.314177 164.354525 -46.325779 164.364229 -46.337378 164.377249 -46.349005 164.386954 -46.3606 164.406411 -46.381481 164.412798 -46.393039 164.422502 -46.404624 164.44196 -46.425489 164.458099 -46.446316 164.467804 -46.45789 164.477507 -46.469461 164.483893 -46.481001 164.493598 -46.492567 164.503251 -46.506425 164.522561 -46.534132 164.541919 -46.559532 164.561277 -46.58492 164.583903 -46.612615 164.606578 -46.638008 164.629253 -46.663388 164.648612 -46.688728 164.674506 -46.718684 164.687478 -46.732515 164.700448 -46.746341 164.71342 -46.760164 164.723075 -46.773953 164.736096 -46.785486 164.74575 -46.79927 164.755454 -46.810767 164.768426 -46.824574 164.778129 -46.836066 164.787834 -46.847556 164.797487 -46.861324 164.807192 -46.872808 164.820213 -46.884319 164.829916 -46.8958 164.839621 -46.907277 164.852493 -46.925612 164.862196 -46.937083 164.87507 -46.955408 164.891259 -46.973756 164.904131 -46.992068 164.917003 -47.010373 164.923391 -47.021797 164.936263 -47.040093 164.949135 -47.058382 164.961957 -47.078936 164.974831 -47.097212 164.987653 -47.11775 165.000525 -47.136012 165.016716 -47.154297 165.029588 -47.172548 165.039192 -47.188497 165.048797 -47.204441 165.058451 -47.218116 165.064738 -47.234022 165.071076 -47.24766 165.08068 -47.263587 165.086967 -47.27948 165.096572 -47.295396 165.102809 -47.313539 165.112364 -47.331705 165.12192 -47.349865 165.128108 -47.370247 165.137613 -47.39065 165.147169 -47.40879 165.150238 -47.420098 165.159743 -47.440481 165.162813 -47.451783 165.172318 -47.472155 165.181822 -47.492518 165.18821 -47.503837 165.197715 -47.524189 165.20722 -47.544532 165.213607 -47.55584 165.223112 -47.576171 165.226182 -47.587443 165.235687 -47.607761 165.242073 -47.619056 165.245143 -47.630319 165.251529 -47.641608 165.254598 -47.652866 165.260936 -47.666396 165.264005 -47.677649 165.270391 -47.688928 165.273461 -47.700176 165.279797 -47.713693 165.282817 -47.727178 165.289154 -47.740688 165.292173 -47.754166 165.298461 -47.76991 165.304797 -47.783409 165.311085 -47.799143 165.317372 -47.814874 165.320342 -47.83057 165.332917 -47.862007 165.345541 -47.891188 165.354898 -47.91809 165.364304 -47.942745 165.370443 -47.965128 165.37663 -47.985271 165.379551 -48.003146 165.382471 -48.021015 165.385391 -48.038877 165.391629 -48.056763 165.394549 -48.074612 165.400788 -48.092485 165.403757 -48.108097 165.406727 -48.123704 165.409648 -48.141531 165.412618 -48.157128 165.415588 -48.172721 165.418607 -48.186085 165.421577 -48.201668 165.42118 -48.21944 165.42415 -48.235013 165.423803 -48.250552 165.426774 -48.266116 165.429694 -48.283894 165.432663 -48.299447 165.435583 -48.317212 165.435186 -48.334943 165.43474 -48.354883 165.437611 -48.374843 165.437114 -48.39698 165.436668 -48.416896 165.439489 -48.439043 165.435676 -48.461124 165.435179 -48.483223 165.434633 -48.507522 165.430721 -48.533987 165.430125 -48.560468 165.426163 -48.58911 165.425468 -48.619968 165.421406 -48.652981 165.417345 -48.685973 165.416601 -48.71897 165.412489 -48.754115 165.408378 -48.789236 165.404267 -48.824332 165.400106 -48.861596 165.395994 -48.896641 165.391883 -48.931662 165.390989 -48.971062 165.387275 -48.988535 165.386829 -49.008217 165.386481 -49.023518 165.382767 -49.040973 165.38237 -49.058449 165.381973 -49.07592 165.378259 -49.093356 165.377912 -49.108632 165.377515 -49.126084 165.377168 -49.14135 165.376771 -49.15879 165.373106 -49.174018 165.372709 -49.191448 165.372361 -49.206694 165.372014 -49.221934 165.3684 -49.234966 165.368051 -49.250198 165.367704 -49.265425 165.36740699999999 -49.278474 165.367059 -49.293692 165.366712 -49.308906 165.366415 -49.321942 165.366066 -49.337148 165.365769 -49.350177 165.365471 -49.363203 165.365174 -49.376225 165.364876 -49.389244 165.364578 -49.402259 165.361013 -49.413074 165.360716 -49.426084 165.360467 -49.436921 165.360169 -49.449924 165.359922 -49.460757 165.359623 -49.473753 165.359375 -49.48458 165.359078 -49.497571 165.358829 -49.508393 165.358532 -49.521376 165.358284 -49.532193 165.357837 -49.551657 165.357588 -49.562468 165.357191 -49.579759 165.356944 -49.590563 165.356547 -49.607845 165.352833 -49.625092 165.352436 -49.642361 165.348722 -49.659596 165.348325 -49.676853 165.347928 -49.694103 165.344262 -49.709165 165.343915 -49.724249 165.340251 -49.739302 165.339903 -49.754376 165.339556 -49.769447 165.335841 -49.786637 165.335494 -49.801697 165.335147 -49.816752 165.33475 -49.833953 165.334402 -49.848999 165.334105 -49.861891 165.333758 -49.876928 165.333361 -49.894107 165.333012 -49.909134 165.332615 -49.9263 165.335537 -49.943489 165.33514 -49.960645 165.334743 -49.977794 165.334495 -49.988509 165.337415 -50.005676 165.337167 -50.016384 165.339888 -50.042103 165.339491 -50.059223 165.339144 -50.074198 165.342115 -50.089196 165.345084 -50.104188 165.344736 -50.119149 165.347657 -50.136268 165.350627 -50.151247 165.35023 -50.168327 165.3532 -50.183295 165.356121 -50.200392 165.355724 -50.217455 165.358644 -50.234539 165.361564 -50.251617 165.361167 -50.268661 165.36077 -50.2857 165.360373 -50.302732 165.363244 -50.321914 165.366164 -50.338961 165.365767 -50.355974 165.368687 -50.373008 165.368291 -50.390009 165.371212 -50.407031 165.370765 -50.426143 165.373685 -50.443152 165.376555 -50.462276 165.379426 -50.481393 165.382297 -50.500502 165.385218 -50.517483 165.388088 -50.536577 165.390959 -50.555664 165.397197 -50.572653 165.400166 -50.587493 165.403137 -50.602329 165.406107 -50.617159 165.409077 -50.631986 165.412047 -50.646807 165.415016 -50.661624 165.417937 -50.678547 165.424125 -50.697603 165.426996 -50.716624 165.429866 -50.735637 165.432738 -50.754642 165.438925 -50.773667 165.445113 -50.792683 165.447985 -50.811665 165.45749 -50.830693 165.463677 -50.849687 165.469866 -50.868672 165.476104 -50.885548 165.485609 -50.904546 165.495163 -50.921435 165.501401 -50.938291 165.510957 -50.955169 165.520562 -50.969941 165.530165 -50.984709 165.53982 -50.997375 165.549524 -51.007941 165.555911 -51.018476 165.575468 -51.03331 165.594974 -51.050233 165.617798 -51.067176 165.647258 -51.084167 165.663646 -51.092674 165.680084 -51.099086 165.703156 -51.105551 165.722911 -51.111988 165.746033 -51.11636 165.769106 -51.122822 165.792278 -51.125101 165.8154 -51.129472 165.841889 -51.131778 165.868428 -51.131991 165.894966 -51.132206 165.911553 -51.13234 165.938092 -51.132554 165.954679 -51.132688 165.984584 -51.130838 166.001171 -51.130972 166.031027 -51.131213 166.047614 -51.131347 166.080886 -51.127432 166.117426 -51.125636 166.150649 -51.123812 166.180604 -51.11987 166.213827 -51.118047 166.2471 -51.114131 166.277055 -51.110188 166.310328 -51.106271 166.346918 -51.102382 166.383508 -51.098491 166.41678 -51.094574 166.45342 -51.08859 166.486743 -51.082579 166.516748 -51.07654 166.550069 -51.070526 166.580125 -51.062391 166.610179 -51.054255 166.640233 -51.046117 166.66697 -51.037951 166.693707 -51.029783 166.717128 -51.021588 166.740597 -51.011293 166.764067 -51.000997 166.784219 -50.990672 166.804421 -50.978246 166.824573 -50.967916 166.841456 -50.955457 166.861658 -50.943021 166.878593 -50.928456 166.896648 -50.913652 167.275366 -50.793788 167.636773 -50.6073 168.063648 -50.423553 168.685367 -50.154646 168.849714 -50.079074 169.01699 -49.993825 169.538563 -49.727041 170.127814 -49.455712 171.012056 -49.076589 171.756449 -48.801285 172.286423 -48.619422 172.695583 -48.497199 173.303232 -48.298451 173.659814 -48.181457 174.480379 -47.932891 174.872698 -47.83127 175.537502 -47.692526 175.956819 -47.596965 176.603641 -47.430025 176.684586 -47.409784 178.33032 -47.047093 178.64661 -46.983468 180.682187 -46.504255 181.149527 -46.372492 182.389396 -45.970896 182.886735 -45.783124 184.197319 -45.295544 184.695737 -45.089964 185.289578 -44.859361 185.625882 -44.750535 185.957221 -44.657345 186.241194 -44.585981 186.665232 -44.485559 186.717083 -44.474465 186.767091 -44.463023 186.820416 -44.451609 186.873791 -44.437812 186.927117 -44.426393 186.980492 -44.412589 187.037135 -44.401196 187.09051 -44.387387 187.147202 -44.373605 187.203894 -44.359819 187.257221 -44.348385 187.310595 -44.334563 187.36397 -44.320738 187.417296 -44.309296 187.470671 -44.295465 187.527364 -44.281661 187.580739 -44.267824 187.634064 -44.256372 187.684122 -44.242497 187.737498 -44.22865 187.760917 -44.219305 187.787605 -44.212379 187.814292 -44.205452 187.84098 -44.198525 187.864351 -44.191566 187.88772 -44.184606 187.914408 -44.177676 187.937778 -44.170715 187.961148 -44.163753 187.984518 -44.15679 188.007889 -44.149826 188.031259 -44.142861 188.054579 -44.138289 188.10132 -44.124356 188.151378 -44.11045 188.201485 -44.094146 188.248226 -44.080203 188.298333 -44.063891 188.348441 -44.047573 188.401815 -44.03368 188.45519 -44.019784 188.505249 -44.005854 188.558674 -43.989551 188.608731 -43.975614 188.662106 -43.961704 188.715481 -43.947791 188.768856 -43.933874 188.825549 -43.919985 188.878924 -43.906062 188.935616 -43.892166 188.992309 -43.878267 189.045734 -43.86193 189.102426 -43.848024 189.155851 -43.831678 189.205908 -43.817703 189.259333 -43.801349 189.306073 -43.787336 189.352813 -43.77332 189.396238 -43.75927 189.436392 -43.742776 189.459763 -43.735763 189.479865 -43.726308 189.503236 -43.719293 189.519971 -43.712216 189.540024 -43.705168 189.560028 -43.700532 189.58008 -43.693483 189.600133 -43.686433 189.620136 -43.681795 189.640139 -43.677156 189.656875 -43.670074 189.676878 -43.665434 189.696881 -43.660794 189.716935 -43.653741 189.736938 -43.649099 189.753673 -43.642014 189.773677 -43.637372 189.793729 -43.630315 189.813732 -43.625673 189.833786 -43.618615 189.853838 -43.611557 189.873842 -43.606913 189.893895 -43.599853 189.913947 -43.592792 189.933951 -43.588147 189.950686 -43.581053 189.970739 -43.57399 189.990743 -43.569344 190.007478 -43.562248 190.027481 -43.5576 190.047485 -43.552952 190.06417 -43.548272 190.084173 -43.543623 190.10086 -43.538942 190.120912 -43.531874 190.137598 -43.527193 190.157602 -43.522542 190.174288 -43.51786 190.194291 -43.513208 190.210976 -43.508526 190.23093 -43.506293 190.247616 -43.501609 190.26762 -43.496957 190.287623 -43.492303 190.307626 -43.48765 190.327579 -43.485416 190.347583 -43.480762 190.367586 -43.476107 190.38759 -43.471453 190.410911 -43.466829 190.430864 -43.464595 190.454184 -43.45997 190.477505 -43.455344 190.500825 -43.45072 190.524146 -43.446094 190.547467 -43.441467 190.570788 -43.436842 190.597425 -43.432246 190.620746 -43.427619 190.644066 -43.422991 190.670704 -43.418394 190.694025 -43.413766 190.720663 -43.409169 190.74735 -43.402148 190.770671 -43.397518 190.797359 -43.390496 190.823997 -43.385897 190.850684 -43.378873 190.877322 -43.374273 190.900693 -43.367216 190.927331 -43.362615 190.954018 -43.355589 190.977338 -43.350956 191.004026 -43.343928 191.027347 -43.339294 191.054034 -43.332265 191.080722 -43.325235 191.107409 -43.318204 191.164102 -43.304171 191.220794 -43.290134 191.277437 -43.278523 191.33418 -43.262052 191.390922 -43.245577 191.447614 -43.231526 191.504356 -43.215043 191.561048 -43.200985 191.621107 -43.184524 191.681166 -43.168058 191.737908 -43.151558 191.791333 -43.13502 191.844758 -43.118479 191.90155 -43.099529 191.954974 -43.082977 192.011716 -43.066454 192.06841 -43.052362 192.121835 -43.035798 192.178577 -43.019261 192.235269 -43.005159 192.295328 -42.988644 192.35202 -42.974534 193 -42.963692 193 -58 157 -58 157 -43.924285</gml:posList>
#</gml:LinearRing>
#</gml:exterior>
#</gml:Polygon>
#</fish:FishGeometry>
#</fish:FD0005_2>
#</gml:featureMember>
#<gml:featureMember>
我现在想将此输出转换为形状,我想我应该使用具有 GML 驱动程序的 ogr2ogr
,甚至可能绕过上面的 XML
。非常感谢任何帮助
library(rgdal)
library(gdalUtils)
ogr2ogr()
readOGR()
我认为你很接近...获取 GML 后,我不得不清理前几个 non-standard 个字符:
gml = substr(albacore,4,nchar(albacore))
从那里,将其作为 GML 文件写入磁盘(可能有一个花哨的技巧 textConnection
或类似的东西来避免写入):
write(gml, "/Users/Benjamin/Desktop/test.gml", sep="")
然后,从文件中读取一层:
data = readOGR("/Users/Benjamin/Desktop/test.gml", "FD0002_2")
>>> OGR data source with driver: GML
>>> Source: "/Users/Benjamin/Desktop/test.gml", layer: "FD0002_2"
>>> with 1 features
>>> It has 12 fields
并写入输出 shapefile:
writeOGR(data, "/Users/Benjamin/Desktop/test.shp", "FD0002_2", driver="ESRI Shapefile")
>>> Warning message:
>>> In writeOGR(data, "/Users/Benjamin/Desktop/test.shp", "FD0002_2", :
>>> Field names abbreviated for ESRI Shapefile driver
您可以使用以下方法查找图层名称:
ogrListLayers("/Users/Benjamin/Desktop/test.gml")