Example #1
0
        /// <summary>
        /// Creates the GeoJSON feature collection from list of <see cref="ArcDeveloper.REST.Core.Interfaces.IFeature"/>.
        /// </summary>
        /// <param name="features">The features.</param>
        /// <returns>A GeoJSON feature collection</returns>
        public static GeoJSONFeatureCollection CreateFeatureCollectionFromList(List <IFeature> features)
        {
            GeoJSONFeatureCollection featCollection = new GeoJSONFeatureCollection();

            foreach (IFeature feat in features)
            {
                featCollection.Features.Add(GeoJSONFeature.CreateFromIFeature(feat));
            }
            return(featCollection);
        }
Example #2
0
        public string GetAsGeoJSON(IRecordSet recordset)
        {
            GeoJSONFeatureCollection jsonFeatures = new GeoJSONFeatureCollection();
            ICursor cur = recordset.get_Cursor(false);

            IFeature f = (IFeature)cur.NextRow();

            if (f != null)
            {
                while (f != null)
                {
                    jsonFeatures.Features.Add(GeoJSONFeature.CreateFromIFeature(f));
                    f = (IFeature)cur.NextRow();
                }
            }

            return("{}");
        }
Example #3
0
        /// <summary>
        /// Creates A GeoJSON feature from an IFeature
        /// </summary>
        /// <param name="feat">The feature.</param>
        /// <returns>A GeoJSON Feature</returns>
        public static GeoJSONFeature CreateFromIFeature(IFeature feat)
        {
            GeoJSONFeature jsonFeature = new GeoJSONFeature();

            jsonFeature.id       = feat.OID.ToString();
            jsonFeature.geometry = GeoJSONGeometry.CreateFromIGeometry(feat.Shape);
            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            for (int i = 0; i < feat.Fields.FieldCount; i++)
            {
                ESRI.ArcGIS.Geodatabase.IField fld = feat.Fields.get_Field(i);
                switch (fld.Name.ToUpper())
                {
                case "SHAPE":
                    break;

                default:
                    string val = "null";
                    if (feat.get_Value(i) != null)
                    {
                        val = feat.get_Value(i).ToString();
                    }
                    if (sb.Length > 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(string.Format("\"{0}\":\"{1}\"", fld.Name, val));

                    break;
                }
            }

            jsonFeature.properties = sb.ToString();
            sb.Append("}");
            jsonFeature.properties = sb.ToString();
            return(jsonFeature);
        }
Example #4
0
        /// <summary>
        /// Creates A GeoJSON feature from an IFeature
        /// </summary>
        /// <param name="feat">The feature.</param>
        /// <returns>A GeoJSON Feature</returns>
        public static GeoJSONFeature CreateFromIFeature(IFeature feat)
        {
            GeoJSONFeature jsonFeature = new GeoJSONFeature();
            jsonFeature.id = feat.OID.ToString();
            jsonFeature.geometry = GeoJSONGeometry.CreateFromIGeometry(feat.Shape);
            StringBuilder sb = new StringBuilder();
            sb.Append("{");

            for (int i = 0; i < feat.Fields.FieldCount; i++)
            {
                ESRI.ArcGIS.Geodatabase.IField fld = feat.Fields.get_Field(i);
                switch (fld.Name.ToUpper())
                {
                    case "SHAPE":
                        break;
                    default:
                        string val = "null";
                        if (feat.get_Value(i) != null)
                            val = feat.get_Value(i).ToString();
                        if(sb.Length > 1)
                            sb.Append(",");
                        sb.Append(string.Format("\"{0}\":\"{1}\"", fld.Name, val));

                        break;
                }
            }

            jsonFeature.properties = sb.ToString();
            sb.Append("}");
            jsonFeature.properties = sb.ToString();
            return jsonFeature;
        }