Exemple #1
0
        public static GeoEnvelope ReadGeoEnvelopeByRegionKey(string iso3166_2RegionCode)
        {
            iso3166_2RegionCode = ConvertRegionCodeToIso3166_2RegionCode(iso3166_2RegionCode);

            String sql = "SELECT geom FROM level1 WHERE HASC_1 = " + "'" + iso3166_2RegionCode + "'";

            Layer resultLayer = _dataSource.ExecuteSQL(sql, null, "");

            if (resultLayer == null)
            {
                return(null);
            }

            if (resultLayer.GetFeatureCount(0) == 0)
            {
                return(null);
            }

            Envelope envelope = new Envelope();

            int ret = resultLayer.GetExtent(envelope, 1);

            GeoEnvelope geoEnvelope = new GeoEnvelope();

            geoEnvelope.SetData(envelope);

            return(geoEnvelope);
        }
Exemple #2
0
        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");
            }
        }
Exemple #3
0
        public static GeoEnvelope ReadGeoEnvelopeByCountryKey(string iso3166_1CountryCode)
        {
            String sql = "SELECT geom FROM level0 WHERE GID_0 = " + "'" + iso3166_1CountryCode + "'";

            Layer resultLayer = _dataSource.ExecuteSQL(sql, null, "");

            if (resultLayer == null)
            {
                return(null);
            }

            if (resultLayer.GetFeatureCount(0) == 0)
            {
                return(null);
            }

            Envelope envelope = new Envelope();

            int ret = resultLayer.GetExtent(envelope, 1);

            GeoEnvelope geoEnvelope = new GeoEnvelope();

            geoEnvelope.SetData(envelope);

            return(geoEnvelope);
        }