static void TestCountryEnvelopeAPI() { string countryCode = "NGA"; GeoEnvelope NigeriaEnvelope = GeoAPI.ReadGeoEnvelopeByCountryKey(countryCode); if (NigeriaEnvelope == null) { Console.WriteLine("failed to get country data for specified country code: {0}", countryCode); return; } // access lat long data List <LonLat> NigeriaEnvelopeLatLonArray = NigeriaEnvelope.GetData(); for (int i = 0; i < NigeriaEnvelopeLatLonArray.Count; i++) { LonLat lonlat = NigeriaEnvelopeLatLonArray[i]; Console.WriteLine("{0} 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 = NigeriaEnvelope.saveToGeoJson("E:/Nigeria_Envelope.geojson"); if (!saveSuccess) { Console.WriteLine("failed to save Nigeria_Envelope.geojson"); } }
static void TestCountryCenterAPI() { string countryCode = "NGA"; GeoPoint NigeriaCenter = GeoAPI.ReadGeoCenterPointByCountryKey(countryCode); if (NigeriaCenter == null) { Console.WriteLine("failed to get country data for specified country code: {0}", countryCode); return; } // access lat long data LonLat NigeriaCenterLonLat = NigeriaCenter.GetData(); Console.WriteLine("Nigeria Center x = {0}, y = {1}", NigeriaCenterLonLat.longitude, NigeriaCenterLonLat.latitude); bool saveSuccess = NigeriaCenter.saveToGeoJson("E:/Nigeria_Center.geojson"); if (!saveSuccess) { Console.WriteLine("failed to save"); } }
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"); } }
public void SetData(Envelope envelope) { LonLat leftBottom = new LonLat(envelope.MinX, envelope.MinY); LonLat rightBottom = new LonLat(envelope.MaxX, envelope.MinY); LonLat rightTop = new LonLat(envelope.MaxX, envelope.MaxY); LonLat leftTop = new LonLat(envelope.MinX, envelope.MaxY); _lonlatArray.Add(leftBottom); _lonlatArray.Add(rightBottom); _lonlatArray.Add(rightTop); _lonlatArray.Add(leftTop); }
public void SetData(Geometry geometry) { _lonlatArray = new List <LonLat>(); wkbGeometryType geomType = geometry.GetGeometryType(); if (geomType != wkbGeometryType.wkbLineString && geomType != wkbGeometryType.wkbLineString25D) { Console.WriteLine("internal error: geometry is not linestring"); return; } int pointCount = geometry.GetPointCount(); for (int i = 0; i < pointCount; i++) { LonLat lonlat = new LonLat(geometry.GetX(i), geometry.GetY(i)); _lonlatArray.Add(lonlat); } }
public GeoPoint() { _lonlat = new LonLat(); }