public bool FromJSonString(string s, GXBaseCollection <SdtMessages_Message> Messages)
        {
            _jsonArr = JSONHelper.ReadJSON <JArray>(s, Messages);
            bool result = _jsonArr != null;

            try
            {
                FromJSONObject((JArray)jsonArr);
                return(result);
            }
            catch (Exception ex)
            {
                GXUtil.ErrorToMessages("FromJson Error", ex, Messages);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public void FromJSON(String s)
        {
            JObject geoObject = JSONHelper.ReadJSON <JObject>(s);

            if (geoObject != null)
            {
                JObject geometry    = (JObject)geoObject["geometry"];
                String  featuretype = "";
                JArray  coords;
                String  wktBuffer = "";
                if (geometry == null)
                {
                    featuretype = (String)geoObject["type"];
                    coords      = (JArray)geoObject["coordinates"];
                }
                else
                {
                    featuretype = (String)geometry["type"];
                    coords      = (JArray)geometry["coordinates"];
                }
                if (featuretype == null)
                {
                    String   locationString = (String)geoObject["Location"];
                    String[] coordinates    = locationString.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    wktBuffer = "POINT(" + coordinates[1].ToString() + " " + coordinates[0].ToString() + ")";
                }
                else
                {
                    setGXGeoType(featuretype);
                    String sep  = "";
                    String sep1 = "";
                    String sep2 = "";
                    switch (GeographicType)
                    {
                    case GeoGraphicTypeValue.Point:
                        wktBuffer  = "POINT";
                        wktBuffer += "(" + JSONPointToWKT(coords) + ")";
                        break;

                    case GeoGraphicTypeValue.Line:
                        wktBuffer  = "LINESTRING";
                        wktBuffer += "(";
                        sep        = "";
                        foreach (JArray jp in coords)
                        {
                            wktBuffer += sep + " " + JSONPointToWKT(jp);
                            sep        = ",";
                        }
                        wktBuffer += ")";
                        break;

                    case GeoGraphicTypeValue.Polygon:
                        wktBuffer  = "POLYGON";
                        wktBuffer += "(";
                        sep1       = "";
                        foreach (JArray jl in coords)
                        {
                            wktBuffer += sep1 + "(";
                            sep        = "";
                            String firstPoint = JSONPointToWKT(jl.GetArray(0));
                            foreach (JArray jp in jl)
                            {
                                String jpS = JSONPointToWKT(jp);
                                wktBuffer += sep + " " + jpS;
                                sep        = ",";
                            }
                            wktBuffer += ")";
                            sep1       = ",";
                        }
                        wktBuffer += ")";
                        break;

                    case GeoGraphicTypeValue.MultiPoint:
                        wktBuffer  = "MULTIPOINT";
                        wktBuffer += "(";
                        sep        = "";
                        foreach (JArray jp in coords)
                        {
                            wktBuffer += sep + " " + JSONPointToWKT(jp);
                            sep        = ",";
                        }
                        wktBuffer += ")";
                        break;

                    case GeoGraphicTypeValue.MultiLine:
                        wktBuffer  = "MULTILINESTRING";
                        wktBuffer += "(";
                        sep1       = "";
                        foreach (JArray jl in coords)
                        {
                            wktBuffer += sep1 + "(";
                            sep        = "";
                            foreach (JArray jp in jl)
                            {
                                wktBuffer += sep + "" + JSONPointToWKT(jp);
                                sep        = ",";
                            }
                            wktBuffer += ")";
                            sep1       = ",";
                        }
                        wktBuffer += ")";
                        break;

                    case GeoGraphicTypeValue.MultiPolygon:
                        wktBuffer  = "MULTIPOLYGON";
                        wktBuffer += "(";
                        sep2       = "";
                        foreach (JArray jm in coords)
                        {
                            wktBuffer += sep2 + "(";
                            sep1       = "";
                            foreach (JArray jl in jm)
                            {
                                wktBuffer += sep1 + "(";
                                sep        = "";
                                String firstPoint = JSONPointToWKT(jl.GetArray(0));
                                foreach (JArray jp in jl)
                                {
                                    wktBuffer += sep + "" + JSONPointToWKT(jp);
                                    sep        = ",";
                                }
                                //wktBuffer += sep + firstPoint;
                                wktBuffer += ")";
                                sep1       = ",";
                            }
                            wktBuffer += ")";
                            sep2       = ",";
                        }
                        wktBuffer += ")";
                        break;

                    default:
                        wktBuffer = "";
                        break;
                    }
                }
                if (wktBuffer.Length > 0)
                {
                    this.FromString(wktBuffer);
                }
            }
        }