{"id":408,"date":"2024-10-23T16:13:55","date_gmt":"2024-10-23T07:13:55","guid":{"rendered":"https:\/\/www.flumen-jp.com\/wordpress\/?p=408"},"modified":"2024-10-24T20:49:51","modified_gmt":"2024-10-24T11:49:51","slug":"ogr2ogr_5","status":"publish","type":"post","link":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2024\/10\/23\/ogr2ogr_5\/","title":{"rendered":"CUI \u3067 GIS (5)"},"content":{"rendered":"\n<p>\u3000\u5f53\u30d6\u30ed\u30b0\u3001\u9577\u3044\u590f\u4f11\u307f\u3092\u7d4c\u3066\u4e45\u65b9\u3076\u308a\u306e\u66f4\u65b0\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u4eca\u56de\u306f\u300cCUI \u3067 GIS\u300d\u306e\u7b2c\uff15\u5f3e\u3067\u3001\u5c0f\u6d41\u57df\u5206\u5272\u3092\u30c6\u30fc\u30de\u306b\u53d6\u308a\u4e0a\u3052\u307e\u3059\u3002<br>\u3000\u4ed5\u4e0a\u304c\u308a\u306e\u30a4\u30e1\u30fc\u30b8\u306f\u4e0b\u56f3\u306e\u3088\u3046\u3067\u3059\u3002\u5c0f\u6d41\u57df\u5206\u5272\u3092\u8868\u3059\u7d19\u306e\u5730\u56f3\u304b\u3089\u3053\u308c\u306e\u591a\u89d2\u5f62\u306e GIS \u30c7\u30fc\u30bf\u306b\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"742\" src=\"https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/watersheds-2-1024x742.png\" alt=\"\" class=\"wp-image-420\" srcset=\"https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/watersheds-2-1024x742.png 1024w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/watersheds-2-300x217.png 300w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/watersheds-2-768x557.png 768w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/watersheds-2.png 1072w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:39px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u3000\u5927\u307e\u304b\u306a\u4f5c\u696d\u306e\u6d41\u308c\u306f<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b9\u30ad\u30e3\u30f3\u3057\u305f\u7d19\u306e\u5730\u56f3\u306b\u5730\u4e0a\u57fa\u6e96\u70b9\uff08GCP\uff1aGround Control Point\uff09\u306e\u5ea7\u6a19\u3092\u4e0e\u3048\u3066\u5e7e\u4f55\u88dc\u6b63\u3057\u305f\u5730\u56f3\uff08GeoTif \u5f62\u5f0f\uff09\u306b\u5909\u63db\u3059\u308b<\/li>\n\n\n\n<li>\u5e7e\u4f55\u88dc\u6b63\u5f8c\u306e\u5730\u56f3\u4e0a\u306e\u5c0f\u6d41\u57df\u306e\u591a\u89d2\u5f62\u306e\u9802\u70b9\u7fa4\u306e\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b<\/li>\n\n\n\n<li>\u4e0a\u306e\u9802\u70b9\u3092\u7d50\u3093\u3067\u5c0f\u6d41\u57df\u6bce\u306e\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b<\/li>\n<\/ol>\n\n\n\n<p>\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5730\u56f3\u306e\u30c7\u30a3\u30b8\u30bf\u30e9\u30a4\u30ba<\/h3>\n\n\n\n<p>\u3000\u5730\u56f3\u306e\u30c7\u30a3\u30b8\u30bf\u30e9\u30a4\u30ba\u306f QGIS \u306e\u30b8\u30aa\u30ea\u30d5\u30a1\u30ec\u30f3\u30b5\u3092\u7528\u3044\u3066\u884c\u3044\u307e\u3057\u305f\u3002\u30b8\u30aa\u30ea\u30d5\u30a1\u30ec\u30f3\u30b5\u306e\u4f7f\u3044\u65b9\u306f <a href=\"https:\/\/docs.qgis.org\/3.34\/ja\/docs\/user_manual\/working_with_raster\/georeferencer.html\">QGIS \u306e\u30aa\u30f3\u30e9\u30a4\u30f3\u30de\u30cb\u30e5\u30a2\u30eb<\/a>\u3092\u3054\u89a7\u4e0b\u3055\u3044\u3002<br>\u3000GCP \u306e\u7def\u5ea6\u30fb\u7d4c\u5ea6\u306f<a href=\"https:\/\/maps.gsi.go.jp\/\">\u5730\u7406\u9662\u5730\u56f3<\/a>\u306e\u30bb\u30f3\u30bf\u30fc\u30de\u30fc\u30af\uff08\uff0b\uff09\u3092\u305d\u306e\u70b9\u306b\u79fb\u52d5\u3055\u305b\u3066\u8868\u793a\u3055\u308c\u308b URL \u304b\u3089\u53d6\u5f97\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"742\" src=\"https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/basemap-1024x742.png\" alt=\"\" class=\"wp-image-410\" srcset=\"https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/basemap-1024x742.png 1024w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/basemap-300x217.png 300w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/basemap-768x557.png 768w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/basemap.png 1072w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:45px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u9802\u70b9\u306e\u5ea7\u6a19\u306e\u53d6\u5f97<\/h3>\n\n\n\n<p>\u3000\u3053\u308c\u3082 QGIS \u4e0a\u3067\u306e\u4f5c\u696d\u3067\u3059\u3002<br>\u3000\u5c5e\u6027\u3068\u3057\u3066\u9802\u70b9\u756a\u53f7 pid \u3092\u6301\u3064 GeoJSON \u5f62\u5f0f\u306e nodes.json \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"742\" src=\"https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/nodes-1-1024x742.png\" alt=\"\" class=\"wp-image-422\" srcset=\"https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/nodes-1-1024x742.png 1024w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/nodes-1-300x217.png 300w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/nodes-1-768x557.png 768w, https:\/\/www.flumen-jp.com\/wordpress\/wp-content\/uploads\/2024\/10\/nodes-1.png 1072w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:39px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5c0f\u6d41\u57df\u6bce\u306e\u30c7\u30fc\u30bf<\/h3>\n\n\n\n<p>\u3000\u96a3\u63a5\u3059\u308b\u5c0f\u6d41\u57df\u306f\u9802\u70b9\u3092\u5171\u6709\u3057\u307e\u3059\u304c\u3001\u624b\u4f5c\u696d\u3067\u30dd\u30ea\u30b4\u30f3\u3092\u62fe\u3046\u3068\u3001\u3053\u308c\u304c\u6b63\u78ba\u306b\u3067\u304d\u306a\u3044\u306e\u3067\u300c<strong>\u30ad\u30fc\u30fc\u30c3\uff01<\/strong>\u300d\u3068\u306a\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u4e0a\u306e\u4f5c\u696d\u3092\u631f\u3093\u3067 Python \u3067\u3053\u306e\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u306f watersheds.py \u3068\u3057\u307e\u3057\u305f\u3002\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u3067 ogr \u304a\u3088\u3073 osr \u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u7528\u3044\u3066\u3044\u308b\u306e\u3067 QGIS \u540c\u68b1\u306e Python \u3092\u4f7f\u3044\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u306e\u74b0\u5883\u8a2d\u5b9a\u3092 watersheds.bat \u3067\u884c\u3063\u3066\u3044\u307e\u3059\uff088 \u884c\u76ee\u306e Python39 \u306f\u9069\u5b9c\u5909\u66f4\u3057\u3066\u4e0b\u3055\u3044\uff09\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>: watersheds.bat\n\n@echo off\nsetlocal\n\nset OSGEO4W_ROOT=C:\\OSGEO4W\nset PATH=%OSGEO4W_ROOT%\\bin;%PATH%\nset PYTHONHOME=%OSGEO4W_ROOT%\\apps\\Python39\ncall %OSGEO4W_ROOT%\\etc\\ini\\gdal.bat\ncall %OSGEO4W_ROOT%\\etc\\ini\\python3.bat\n\nif exist watershed.json (del watershed.json) \npython watersheds.py\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># watersheds.py \n\nfrom osgeo import ogr\nfrom osgeo import osr\n\n# https:\/\/gdal.org\/en\/latest\/api\/python\/osgeo.ogr.html\n# https:\/\/gdal.org\/en\/latest\/api\/python\/osgeo.osr.html\n\nwatersheds = (\n    {&quot;name&quot;: &quot;A&quot;, &quot;nodes&quot;: [4, 5, 6, 7, 15, 16, 17, 18,\n                            8, 36, 35, 34, 4]},\n    {&quot;name&quot;: &quot;B&quot;, &quot;nodes&quot;: [1, 3, 2, 4, 34, 35, 36, 8, 18,\n                            9, 10, 11, 12, 13, 14, 1]},\n    {&quot;name&quot;: &quot;C&quot;, &quot;nodes&quot;: [2, 19, 20, 21, 22, 23, 24, 16,\n                            15, 7, 6, 5, 4, 2]},\n    {&quot;name&quot;: &quot;D&quot;, &quot;nodes&quot;: [21, 25, 26, 27, 28, 29, 24, 23, 22, 21]},\n    {&quot;name&quot;: &quot;E&quot;, &quot;nodes&quot;: [26, 30, 31, 32, 33, 27, 26]}\n)\n\ndriver = ogr.GetDriverByName(&quot;GeoJSON&quot;)\ndataSource = driver.Open(&quot;nodes.json&quot;)\nlayer = dataSource.GetLayer(&quot;nodes&quot;)\nfeature_count = layer.GetFeatureCount()\n\npts = []\nfor _ in range(feature_count):\n    feature  = layer.GetNextFeature()\n    geometry = feature.GetGeometryRef()\n    x = geometry.GetX()\n    y = geometry.GetY()\n    pts.append([x, y])\n\nlayer = None  \ndataSource = None\n\nsrs = osr.SpatialReference()\nsrs.ImportFromEPSG(4612)\n\ndriver = ogr.GetDriverByName(&quot;GeoJSON&quot;)\ndataSource = driver.CreateDataSource(&quot;watersheds.json&quot;)\nlayer = dataSource.CreateLayer(&quot;watersheds&quot;, srs,\n                        geom_type=ogr.wkbPolygon)\n\nnameField = ogr.FieldDefn(&quot;name&quot;, ogr.OFTString)\nlayer.CreateField(nameField)\n\nfeatureDefn = layer.GetLayerDefn()\nfor watershed in watersheds:\n    ring = ogr.Geometry(ogr.wkbLinearRing)\n    for node in watershed[&quot;nodes&quot;]:\n        pt = pts[node - 1]\n        ring.AddPoint_2D(pt[0], pt[1])\n    poly = ogr.Geometry(ogr.wkbPolygon)\n    poly.AddGeometry(ring)\n    feature = ogr.Feature(featureDefn)\n    feature.SetGeometry(poly)\n    feature.SetField(&quot;name&quot;, watershed[&quot;name&quot;])\n    layer.CreateFeature(feature)\n    feature = None\n\nlayer = None\ndataSource = None\n<\/code><\/pre><\/div>\n\n\n\n<p>\u3000watersheds.py \u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u8aac\u660e\u3059\u308b\u3068\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>9 \uff5e 18 \u884c\u76ee\u306f\u5404\u5c0f\u6d41\u57df\u306e\u591a\u89d2\u5f62\u3092\u69cb\u6210\u3059\u308b\u9802\u70b9\u3092 QGIS \u3067\u8868\u793a\u3057\u305f nodes \u306e\u9802\u70b9\u756a\u53f7\u3092\u78ba\u8a8d\u3057\u306a\u304c\u3089\u3001\u53cd\u6642\u8a08\u56de\u308a\u3067\u62fe\u3063\u305f\u914d\u5217\u3068\u6d41\u57df\u540d\u306e\u8f9e\u66f8\u306e\u914d\u5217 watersheds \u306b\u8a18\u61b6\u3057\u307e\u3059<\/li>\n\n\n\n<li>20 \uff5e 34 \u884c\u76ee\u306f nodes.json \u3092\u8aad\u307f\u8fbc\u3093\u3067\u5168\u3066\u306e\u9802\u70b9\u306e\u7def\u5ea6\u30fb\u7d4c\u5ea6\u306e\u914d\u5217\u306e\u914d\u5217\u3092 pts \u306b\u53ce\u3081\u307e\u3059<\/li>\n\n\n\n<li>36 \uff5e 37 \u884c\u76ee\u306f EPSG \u30b3\u30fc\u30c9\u304c 4612 \u3067\u3042\u308b JGD2000 \u306e\u7a7a\u9593\u53c2\u7167\u7cfb\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 \u3092 srs \u306b\u8a2d\u5b9a\u3057\u307e\u3059<\/li>\n\n\n\n<li>39\uff5e45 \u884c\u76ee\u3067\u306f\u30ec\u30a4\u30e4\u30fc\u540d\u3001\u5730\u7269\u306e\u30bf\u30a4\u30d7\u3001\u7a7a\u9593\u53c2\u7167\u7cfb\u3092\u6307\u5b9a\u3057\u3001name \u5c5e\u6027\u3092\u6301\u3064 waterhseds.json \u3092\u65b0\u898f\u306b\u767b\u9332\u3057\u307e\u3059<\/li>\n\n\n\n<li>47\uff5e59 \u884c\u76ee\u3067\u306f\u5404\u5c0f\u6d41\u57df\u306b\u3064\u3044\u3066\u8f9e\u66f8\u306e\u914d\u5217 watersheds \u306b\u57fa\u3065\u3044\u3066\u30dd\u30ea\u30b4\u30f3\u3092\u4f5c\u6210\u3057\u3001name \u5c5e\u6027\u3092\u4e0e\u3048\u307e\u3059\u3002\u3064\u307e\u308a waterhseds.json \u306b\u5404\u5c0f\u6d41\u57df\u306e\u60c5\u5831\u3092\u66f8\u304d\u8fbc\u3093\u3067\u3044\u307e\u3059<\/li>\n<\/ul>\n\n\n\n<p>\u3000\u4ee5\u524d\u306e\u8a18\u4e8b\u3067\u300c\u5b9a\u578b\u306e\u51e6\u7406\u304c\u591a\u3044\u306e\u3067\u5b9f\u969b\u306b\u8a18\u8ff0\u3059\u308b\u30b3\u30fc\u30c9\u306f\u308f\u305a\u304b\u300d\u7684\u306a\u3053\u3068\u3092\u8ff0\u3079\u307e\u3057\u305f\u304c\u3001\u3053\u3053\u3067\u3082\u4ed6\u6240\u3067\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u306b\u624b\u3092\u52a0\u3048\u3066\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u306a\u306e\u3067\u6c4e\u7528\u6027\u3092\u8003\u3048\u305a\u306b\u6c17\u8efd\u306b\u4f7f\u3044\u6368\u3066\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u3000\u305d\u3057\u3066\u6bce\u56de\u5f37\u8abf\u3057\u307e\u3059\u304c\u3001\u9802\u70b9\u306e\u4f4d\u7f6e\u304c\u3065\u308c\u3066\u3044\u305f\u3001\u5c0f\u6d41\u57df\u3092\u69cb\u6210\u3059\u308b\u9802\u70b9\u304c\u9593\u9055\u3048\u3066\u3044\u305f\u306a\u3069\u304c\u767a\u751f\u3057\u3066\u3082\u7c21\u5358\u306b\u76f4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff08\u5b9f\u969b\u306b\u305d\u3046\u306a\u3063\u305f\uff09\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u5f53\u30d6\u30ed\u30b0\u3001\u9577\u3044\u590f\u4f11\u307f\u3092\u7d4c\u3066\u4e45\u65b9\u3076\u308a\u306e\u66f4\u65b0\u3067\u3059\u3002 \u3000\u4eca\u56de\u306f\u300cCUI \u3067 GIS\u300d\u306e\u7b2c\uff15\u5f3e\u3067\u3001\u5c0f\u6d41\u57df\u5206\u5272\u3092\u30c6\u30fc\u30de\u306b\u53d6\u308a\u4e0a\u3052\u307e\u3059\u3002\u3000\u4ed5\u4e0a\u304c\u308a\u306e\u30a4\u30e1\u30fc\u30b8\u306f\u4e0b\u56f3\u306e\u3088\u3046\u3067\u3059\u3002\u5c0f\u6d41\u57df\u5206\u5272\u3092\u8868\u3059\u7d19\u306e\u5730\u56f3\u304b\u3089\u3053\u308c\u306e\u591a\u89d2\u5f62\u306e GIS \u30c7\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[18,22,19,26],"class_list":["post-408","post","type-post","status-publish","format-standard","hentry","category-it","tag-cui","tag-gis","tag-python","tag-python_api"],"_links":{"self":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=408"}],"version-history":[{"count":23,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":443,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/408\/revisions\/443"}],"wp:attachment":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}