{"id":268,"date":"2024-04-18T13:50:00","date_gmt":"2024-04-18T04:50:00","guid":{"rendered":"https:\/\/www.flumen-jp.com\/wordpress\/?p=268"},"modified":"2024-10-23T15:02:43","modified_gmt":"2024-10-23T06:02:43","slug":"ogr2ogr_4","status":"publish","type":"post","link":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2024\/04\/18\/ogr2ogr_4\/","title":{"rendered":"CUI \u3067 GIS (4)"},"content":{"rendered":"\n<p>\u3000\u524d\u56de\u7528\u3044\u305f <a href=\"https:\/\/www.e-stat.go.jp\/gis\">e-Stat \u7d71\u8a08\u5730\u7406\u60c5\u5831\u30b7\u30b9\u30c6\u30e0<\/a>\u306e\u30c7\u30fc\u30bf\u306f 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u6bce\u306b\u30a2\u30fc\u30ab\u30a4\u30d6\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u3001<a href=\"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2024\/04\/17\/ogr2ogr_3\/\">\u524d\u56de\u306e\u4e8b\u4f8b<\/a>\u306e\u5bfe\u8c61\u6d41\u57df\uff08clipsrc\uff09\u3092\u30ab\u30f4\u30a1\u30fc\u3059\u308b 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u3092\u3069\u3046\u3084\u3063\u3066\u8abf\u3079\u305f\u304b\u3001\u306b\u3064\u3044\u3066\u8a18\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Python API<\/h3>\n\n\n\n<p>\u3000ogr2ogr \u306f\u5730\u7406\u7a7a\u9593\u30c7\u30fc\u30bf\u3092\u62bd\u8c61\u5316\u3059\u308b\u30af\u30e9\u30b9\u30e9\u30a4\u30d6\u30e9\u30ea <a href=\"https:\/\/gdal.org\/\">GDAL<\/a> \u3092\u7528\u3044\u3066 C++ \u3067\u4f5c\u6210\u3055\u308c\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002\u540c\u69d8\u306b Python \u3067\u3082 GDAL \u3092\u7528\u3044\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u81ea\u4f5c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u306e\u74b0\u5883\u3082 QGIS \u306b\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u3055\u3089\u306b\u8a00\u3048\u3070\u3001<a href=\"https:\/\/gdal.org\/programs\/ogrmerge.html\">ogrmerge.py<\/a> \u306a\u3069\u3044\u304f\u3064\u304b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304c Python \u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br>\u3000GDAL \u306f\u591a\u6a5f\u80fd\u306a\u306e\u3067<a href=\"https:\/\/gdal.org\/api\/python\/vector_api.html\">\u5168\u3066<\/a>\u3092\u628a\u63e1\u3059\u308b\u306e\u306f\u56f0\u96e3\u3067\u3059\u304c\u3001\u4e3b\u306a\u4f7f\u7528\u6cd5\u306b\u3064\u3044\u3066<a href=\"https:\/\/pcjericks.github.io\/py-gdalogr-cookbook\/index.html\">\u30af\u30c3\u30af\u30d6\u30c3\u30af<\/a>\uff08\u82f1\u6587 org\uff09\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u30cb\u30fc\u30ba\u304c\u4f4e\u3044\u306e\u304b 2.7 \u7248\u306e Python \u3067\u306e\u8a18\u4e8b\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u308c\u3067\u3082\u5341\u5206\u306b\u53c2\u8003\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">meshCode.py<\/h3>\n\n\n\n<p>\u3000\u5192\u982d\u306e\u7528\u9014\u306e\u305f\u3081\u306b Python API \u3092\u7528\u3044\u3066\u8a18\u8ff0\u3057\u305f meshCode.py \u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<br>\u3000\u5165\u529b\u30d5\u30a1\u30a4\u30eb\uff08file_input\uff09\u5185\u306e\u7279\u5b9a\u306e\u30ec\u30a4\u30e4\u30fc\u306e\u5730\u7269\uff08feature\uff09\u3042\u308b\u3044\u306f\u30ec\u30a4\u30e4\u30fc\u5185\u306e\u5730\u7269\u7fa4\u3092\u5305\u542b\u3059\u308b 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u306e\u30b3\u30fc\u30c9\u3092\u5217\u6319\u3057\u307e\u3059\u3002file_input \u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f Shapefile\u3001SQLite\u3001GeoJSON \u3042\u308b\u3044\u306f GeoPackge \u306e\u4f55\u308c\u304b\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br>\u300033 \u884c\u76ee\u4ee5\u964d\u306e\u884c\u3067\u5730\u7269\u6bce\u306e\u5317\u897f\u7aef\u30fb\u5357\u6771\u7aef\u306e\u5ea7\u6a19\uff08envelope\uff09\u304b\u3089 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u306e\u30b3\u30fc\u30c9\u3092\u5272\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import os\nimport sys\nfrom osgeo import ogr\n\nif __name__ == &#39;__main__&#39;:\n\n    file_input = sys.argv[1]\n    if not os.path.exists(file_input):\n        sys.exit(f&quot;\\n {file_input} not found.&quot;)\n\n    for driver_name in (&quot;ESRI Shapefile&quot;, &quot;SQLite&quot;, &quot;GeoJSON&quot;, &quot;GPKG&quot;):\n        driver = ogr.GetDriverByName(driver_name)\n        layers = driver.Open(file_input, 0)\n        if not layers is None: break\n    if layers is None:\n        sys.exit(f&quot;\\n can not open {file_input}.&quot;)\n\n    if layers.GetLayerCount() == 1:\n        layer = layers.GetLayer(0)\n        layer_name = layer.GetName()\n    else:\n        if len(sys.argv) == 1:\n            sys.exit(&quot;\\n please input layer name.&quot;)\n        layer_names = []\n        for layer in layers:\n            layer_names.append(layer.GetName())\n        layer_name = sys.argv[1]\n        if layer_name in layer_names:\n            layer = layers.GetLayer(layer_name)\n        else:\n            sys.exit(f&quot;\\n {layer_name} no such layer.&quot;)\n\n    feature_count = layer.GetFeatureCount()\n\n    code_set = []\n    for idx in range(feature_count):\n        feature  = layer.GetNextFeature()\n        geometry = feature.GetGeometryRef()\n        envelope = geometry.GetEnvelope()\n        codes = []\n        for lon in [envelope[0], envelope[1]]:\n            for lat in [envelope[2], envelope[3]]:\n                code = f&quot;{int(lat * 1.5)}{int(lon - 100)}&quot; # 1st order\n                if not code in codes:\n                    codes.append(code)\n                if not code in code_set:\n                    code_set.append(code)\n\n        print(f&quot;fid:{idx + 1:3d}   {codes}&quot;)\n\n    if feature_count &gt; 1:\n        print(f&quot;\\n    union {code_set}&quot;)<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">meshCode.bat<\/h3>\n\n\n\n<p>\u30003 \u884c\u76ee\u3067\u5ba3\u8a00\u3057\u3066\u3044\u308b ogr \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u305f\u3081\u3001QGIS \u540c\u68b1\u306e Python \u3092\u4f7f\u7528\u3059\u308b\u306e\u3067\u3001\u30d0\u30c3\u30c1\u30d5\u30a1\u30a4\u30eb meshCode.bat \u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002meshCode.py \u306f\u30ec\u30a4\u30e4\u30fc\u304c 1 \u3064\u3057\u304b\u306a\u3044\u5834\u5408\u306f\u30ec\u30a4\u30e4\u30fc\u540d\u3092\u7701\u7565\u3067\u304d\u308b\u4ed5\u69d8\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>@echo off\nsetlocal\nset OSGEO4W_ROOT=C:\\OSGEO4W\nset PATH=%OSGEO4W_ROOT%\\bin;%PATH%\ncall %OSGEO4W_ROOT%\\etc\\ini\\gdal.bat\ncall %OSGEO4W_ROOT%\\etc\\ini\\python3.bat\n\nif not &quot;%1&quot; == &quot;&quot; (\n    python meshCode.py %*\n) else (\n    echo.\n    echo Usage : %~n0 src_dataset_name [layer_name]\n)<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u524d\u56de\u306e\u4e8b\u4f8b\u3067\u306f<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>meshCode someBasin.gpkg<\/code><\/pre><\/div>\n\n\n\n<p>\u3068\u3057\u3066\u30ec\u30a4\u30e4\u30fc\u5185\u306e\u5168\u3066\u306e\u5c0f\u6d41\u57df\u3092\u5305\u542b\u3059\u308b 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u306e\u30b3\u30fc\u30c9 5239\u30015339 \u3092\u5f97\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h3>\n\n\n\n<p>\u3000\u5148\u306b\u300c33 \u884c\u76ee\u4ee5\u964d\u306e\u884c\u3067\uff5e\u300d\u3068\u8a18\u3057\u307e\u3057\u305f\u304c\u3001\u9006\u306b\u3053\u308c\u3088\u308a\u524d\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u554f\u984c\u306b\u3088\u3089\u306a\u3044\u5b9a\u578b\u306e\u51e6\u7406\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u5b9f\u8cea\u306f 20 \u884c\u8db3\u3089\u305a\u3067\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u308c\u307b\u3069\u6577\u5c45\u306f\u9ad8\u304f\u306a\u3044\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<br>\u3000\u306a\u304a\u3001Python \u306e\u5fc3\u5f97\u306e\u3042\u308b\u4eba\u306f\u3068\u304b\u304f\u81ea\u4f5c\u306b\u8d70\u308a\u52dd\u3061\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u304a\u52e7\u3081\u3067\u304d\u307e\u305b\u3093\u3002\u51fa\u6765\u5408\u3044\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u6700\u5927\u9650\u6d3b\u7528\u3057\u3066\u3001\u8db3\u3089\u3056\u308b\u6a5f\u80fd\u3092\u81ea\u4f5c\u3067\u88dc\u8db3\u3059\u308b\u3068\u3044\u3046\u30b9\u30bf\u30f3\u30b9\u304c\u30bf\u30a4\u30d1\u7684\u306b\u512a\u308c\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u307e\u3001\u98fd\u304f\u3053\u3068\u306a\u304d\u30de\u30a6\u30b9\u64cd\u4f5c\u306e\u30bf\u30a4\u30d1\u306f\u6700\u4f4e\u30ec\u30d9\u30eb\u3067\u3059\u304c\u30fb\u30fb\u30fb<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u524d\u56de\u7528\u3044\u305f e-Stat \u7d71\u8a08\u5730\u7406\u60c5\u5831\u30b7\u30b9\u30c6\u30e0\u306e\u30c7\u30fc\u30bf\u306f 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u6bce\u306b\u30a2\u30fc\u30ab\u30a4\u30d6\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u3001\u524d\u56de\u306e\u4e8b\u4f8b\u306e\u5bfe\u8c61\u6d41\u57df\uff08clipsrc\uff09\u3092\u30ab\u30f4\u30a1\u30fc\u3059\u308b 1 \u6b21\u30e1\u30c3\u30b7\u30e5\u3092\u3069\u3046\u3084\u3063\u3066\u8abf\u3079\u305f\u304b\u3001\u306b\u3064\u3044\u3066\u8a18\u3057\u307e\u3059\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[18,22,19,26],"class_list":["post-268","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\/268","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=268"}],"version-history":[{"count":6,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":407,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions\/407"}],"wp:attachment":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}