private void SetDataFromPolygon(Geometry geometry) { GeoPolygon polygon = new GeoPolygon(); polygon.SetData(geometry); _polygonArray.Add(polygon); }
static void TestCountryPolygonAPI() { // test polygon API string countryCode = "NGA"; double simplifyTolerlance = 0.0; GeoMultiPolygon fullNigeriaData = GeoAPI.ReadGeoPolygonByCountryKey(countryCode, simplifyTolerlance); if (fullNigeriaData == null) { Console.WriteLine("failed to get country data for specified country code: {0}", countryCode); return; } fullNigeriaData.saveToGeoJson("E:/Full_Nigeria.geojson"); simplifyTolerlance = 0.02; GeoMultiPolygon simplifiedNigeriaDataPreserveTopology = GeoAPI.ReadGeoPolygonByCountryKey(countryCode, simplifyTolerlance); if (simplifiedNigeriaDataPreserveTopology == null) { Console.WriteLine("failed to get country data for specified country code: {0}", countryCode); return; } // access lat long data for (int i = 0; i < simplifiedNigeriaDataPreserveTopology.GetData().Count; i++) { GeoPolygon polygon = simplifiedNigeriaDataPreserveTopology.GetData()[i]; for (int j = 0; j < polygon.GetData().Count; j++) { GeoLineString lineString = polygon.GetData()[j]; for (int k = 0; k < lineString.GetData().Count; k++) { LonLat lonlat = lineString.GetData()[k]; Console.WriteLine("{0}d th x = {1}, y = {2}", i, lonlat.longitude, lonlat.latitude); } } } // how to test result // we can save result to geojson file, open it in GIS tool(for example QGIS) and view it. bool saveSuccess = simplifiedNigeriaDataPreserveTopology.saveToGeoJson("E:/Simplified_Nigeria_0.02.geojson"); if (!saveSuccess) { Console.WriteLine("failed to save"); } }
private void SetDataFromMultiPolygon(Geometry geometry) { int geomCount = geometry.GetGeometryCount(); for (int i = 0; i < geomCount; i++) { Geometry geom = geometry.GetGeometryRef(i); if (geom.GetGeometryType() == wkbGeometryType.wkbPolygon) { GeoPolygon polygon = new GeoPolygon(); polygon.SetData(geom); _polygonArray.Add(polygon); } else { Console.WriteLine("unknown geometry type!"); } } }