Ejemplo n.º 1
0
        public static string getproj(List <string> args)
        {
            if (args.Count < 0)
            {
                return("getproj requires at least 1 argument");
            }

            string authCode   = args[0];
            string projection = AutoProjection.GetProjection(authCode);

            return(projection);
        }
Ejemplo n.º 2
0
        public static string quack(List <string> args)
        {
            try
            {
                double lat = Convert.ToDouble(args[0]);
                double lon = Convert.ToDouble(args[1]);

                if (args.Count > 2)
                {
                    string unit       = args[2];
                    string projection = AutoProjection.GetProjection(lat, lon, unit);
                    return(projection);
                }
                else
                {
                    string projection = AutoProjection.GetProjection(lat, lon);
                    return(projection);
                }
            }
            catch
            {
                return("What the quack? You didn't quack right. Enter 'quack latitude longitude unit(optional)'. QUACK!");
            }
        }
Ejemplo n.º 3
0
        public static bool GetProjectionFromGeoJson(string fileName, out string projectionName, out string projection)
        {
            string       geoJson = File.ReadAllText(fileName);
            ProtoGeoJSON obj     = JsonConvert.DeserializeObject <ProtoGeoJSON>(geoJson);

            projectionName = string.Empty;
            projection     = string.Empty;
            ICRSObject crs = null;

            switch (obj.Type)
            {
            case "FeatureCollection":
                GFeatureCollection features = JsonConvert.DeserializeObject <GFeatureCollection>(geoJson);
                crs = features.CRS;
                break;

            case "Feature":
                GFeature feature = JsonConvert.DeserializeObject <GFeature>(geoJson);
                crs = feature.CRS;
                break;

            case "MultiPolygon":
                GMultiPolygon multiPoly = JsonConvert.DeserializeObject <GMultiPolygon>(geoJson);
                crs = multiPoly.CRS;
                break;

            case "Polygon":
                GPolygon poly = JsonConvert.DeserializeObject <GPolygon>(geoJson);
                crs = poly.CRS;
                break;

            default:
                break;
            }

            if (crs is NamedCRS)
            {
                NamedCRS nCrs = crs as NamedCRS;
                object   value;
                if (nCrs.Properties.TryGetValue("name", out value))
                {
                    string name = value as string;
                    if (name != null)
                    {
                        name = name.ToLower();
                        if (name.EndsWith("3857"))
                        {
                            projectionName = "EPSG:3857 Pseudo-Mercator";
                            projection     = CoordinateConverter.WebMercator.WKT;
                            return(true);
                        }
                        else
                        {
                            int    index      = name.IndexOf("epsg::");
                            string epsgStr    = name.Substring(index);
                            string authNumber = epsgStr.Substring(epsgStr.IndexOf("::") + 2);
                            projection = AutoProjection.GetProjection(authNumber);
                            if (projection != string.Empty)
                            {
                                projectionName = string.Format("EPSG:{0}", authNumber);
                                return(true);
                            }
                        }
                    }
                }
            }

            projectionName = "EPSG:4326 Lat-Long";
            projection     = CoordinateConverter.WGS84.WKT;
            return(true);
        }