GeoJson⇒ArcGIS


ArcGIS Gateway
https://github.com/davetimmins/ArcGIS.PCL

Install-Package ArcGIS.PCL
Install-Package ServiceStack.Text

取り敢えずGeoJsonからArcObjects RecordSetに変える。
RecordSetにすればShapeFile化できるし。

逆変換は下記
ArcGIS⇒GeoJson

ライブラリ参照

using ArcGIS.ServiceModel;
using ArcGIS.ServiceModel.Common;
using ArcGIS.ServiceModel.GeoJson;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ServiceStack.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;

コード カラム定義Jsonを以下に作るかが課題かなぁ。

public void Test(string geoJson)
{
  var agsJson = Convert<GeoJsonPolygon, Polygon>(geoJson);

  string json = JsonSerializer.SerializeToString<List<Feature<IGeometry>>>(agsJson);

  //json = json.Replace("\"__type\":\"ArcGIS.ServiceModel.Common.Polygon, ArcGIS.ServiceModel\",", "");

  string jsonBase =
@"{
""displayFieldName"": ""JCODE"",
""fieldAliases"": {
""OBJECTID"": ""OBJECTID"",
""JCODE"": ""JCODE"",
""KEN"": ""KEN"",
""SICHO"": ""SICHO"",
""GUN"": ""GUN"",
""SEIREI"": ""SEIREI"",
""SIKUCHOSON"": ""SIKUCHOSON"",
""CITY_ENG"": ""CITY_ENG"",
""P_NUM"": ""P_NUM"",
""H_NUM"": ""H_NUM"",
""Shape.STArea()"": ""Shape.STArea()"",
""Shape.STLength()"": ""Shape.STLength()""
},
""geometryType"": ""esriGeometryPolygon"",
""spatialReference"": {
""wkid"": 104111,
""latestWkid"": 4612
},
""fields"": [
{
""name"": ""OBJECTID"",
""type"": ""esriFieldTypeOID"",
""alias"": ""OBJECTID""
},
{
""name"": ""JCODE"",
""type"": ""esriFieldTypeString"",
""alias"": ""JCODE"",
""length"": 5
},
{
""name"": ""KEN"",
""type"": ""esriFieldTypeString"",
""alias"": ""KEN"",
""length"": 10
},
{
""name"": ""SICHO"",
""type"": ""esriFieldTypeString"",
""alias"": ""SICHO"",
""length"": 20
},
{
""name"": ""GUN"",
""type"": ""esriFieldTypeString"",
""alias"": ""GUN"",
""length"": 20
},
{
""name"": ""SEIREI"",
""type"": ""esriFieldTypeString"",
""alias"": ""SEIREI"",
""length"": 20
},
{
""name"": ""SIKUCHOSON"",
""type"": ""esriFieldTypeString"",
""alias"": ""SIKUCHOSON"",
""length"": 20
},
{
""name"": ""CITY_ENG"",
""type"": ""esriFieldTypeString"",
""alias"": ""CITY_ENG"",
""length"": 50
},
{
""name"": ""P_NUM"",
""type"": ""esriFieldTypeInteger"",
""alias"": ""P_NUM""
},
{
""name"": ""H_NUM"",
""type"": ""esriFieldTypeInteger"",
""alias"": ""H_NUM""
},
{
""name"": ""Shape.STArea()"",
""type"": ""esriFieldTypeDouble"",
""alias"": ""Shape.STArea()""
},
{
""name"": ""Shape.STLength()"",
""type"": ""esriFieldTypeDouble"",
""alias"": ""Shape.STLength()""
}
],
""features"": 
  FEATURE_REPLACE
}".Replace("FEATURE_REPLACE", json);


  Debug.Print(json);

  using (ComReleaser com = new ComReleaser())
  {
    IJSONReader jsonReader = new JSONReaderClass();
    com.ManageLifetime(jsonReader);

    jsonReader.ReadFromString(jsonBase);

    IJSONConverterGdb jsonConverterGdb = new JSONConverterGdbClass();
    com.ManageLifetime(jsonConverterGdb);

    IPropertySet originalToNewFieldMap;
    IRecordSet recordSet;
    jsonConverterGdb.ReadRecordSet(jsonReader, null, null, out recordSet, out originalToNewFieldMap);
    com.ManageLifetime(recordSet);
    com.ManageLifetime(originalToNewFieldMap);

    Debug.Print("Rows:{0}", recordSet.Table.RowCount(null));
  }
}//end method

List<Feature<IGeometry>> Convert<TGeoJSON, TGeometry>(String data)
  where TGeoJSON : IGeoJsonGeometry
  where TGeometry : IGeometry
{
  var featureCollection = JsonSerializer.DeserializeFromString<FeatureCollection<TGeoJSON>>(data);
  var features = featureCollection.ToFeatures();
  return features;
}//end method
カテゴリー: 開発 タグ: パーマリンク