Ejemplo n.º 1
0
        public static string WriteFeature(IGeoJsonFeatureStyle style, IFeatureDataRecord feature)
        {
            StringBuilder sb = new StringBuilder();

            WriteFeature(sb, style, feature);
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public static void WriteFeature(StringBuilder sb, IGeoJsonFeatureStyle style, IFeatureDataRecord feature)
        {
            IGeometry g = style.PreProcessGeometries
                              ? style.GeometryPreProcessor(feature.Geometry)
                              : feature.Geometry;

            sb.Append("{");
            sb.Append("\"type\":\"Feature\",");
            if (feature.HasOid)
            {
                sb.Append(JsonUtility.FormatJsonAttribute("id", feature.GetOid()));
                sb.Append(",");
            }

            sb.Append("\"properties\":");
            WriteFeatureAttributes(sb, style, feature);
            sb.Append(",");

            if (style.IncludeBBox)
            {
                sb.Append("\"bbox\":");
                WriteExtents(sb, g.Extents, style.CoordinateNumberFormatString);
                sb.Append(",");
            }

            /* Ideally this should be higher up e.g at the layer level but we dont currently
             * have anywhere where we can group features by layer.
             * It still complies with the spec but will be considerably more verbose */

            if (g.SpatialReference != null || !string.IsNullOrEmpty(g.Srid))
            {
                sb.Append("\"crs\":");
                WriteNamedCrs(sb,
                              g.SpatialReference != null
                                  ? g.SpatialReference.Name
                                  : "EPSG:" + SridMap.DefaultInstance.Process(g.SpatialReference, 0));
                sb.Append(",");
            }

            sb.Append("\"geometry\":");
            WriteGeometry(sb, g, style.CoordinateNumberFormatString);

            sb.Append("}");
            sb.AppendLine();
        }
        public static void WriteFeature(StringBuilder sb, IGeoJsonFeatureStyle style, IFeatureDataRecord feature)
        {
            IGeometry g = style.PreProcessGeometries
                              ? style.GeometryPreProcessor(feature.Geometry)
                              : feature.Geometry;
            sb.Append("{");
            sb.Append("\"type\":\"Feature\",");
            if (feature.HasOid)
            {
                sb.Append(JsonUtility.FormatJsonAttribute("id", feature.GetOid()));
                sb.Append(",");
            }

            sb.Append("\"properties\":");
            WriteFeatureAttributes(sb, style, feature);
            sb.Append(",");

            if (style.IncludeBBox)
            {
                sb.Append("\"bbox\":");
                WriteExtents(sb, g.Extents, style.CoordinateNumberFormatString);
                sb.Append(",");
            }

            /* Ideally this should be higher up e.g at the layer level but we dont currently 
             * have anywhere where we can group features by layer. 
             * It still complies with the spec but will be considerably more verbose */

            if (g.SpatialReference != null || !string.IsNullOrEmpty(g.Srid))
            {
                sb.Append("\"crs\":");
                WriteNamedCrs(sb,
                              g.SpatialReference != null
                                  ? g.SpatialReference.Name
                                  : "EPSG:" + SridMap.DefaultInstance.Process(g.SpatialReference, 0));
                sb.Append(",");
            }

            sb.Append("\"geometry\":");
            WriteGeometry(sb, g, style.CoordinateNumberFormatString);

            sb.Append("}");
            sb.AppendLine();
        }
Ejemplo n.º 4
0
 private static void WriteFeatureAttributes(StringBuilder sb, IGeoJsonFeatureStyle style,
                                            IFeatureDataRecord feature)
 {
     sb.Append("{");
     if (style.IncludeAttributes)
     {
         IDictionary <string, object> attributes = style.AttributeExtractionDelegate(feature);
         int i = 0;
         foreach (KeyValuePair <string, object> kvp in attributes)
         {
             sb.Append(JsonUtility.FormatJsonAttribute(kvp.Key, kvp.Value));
             if (i < attributes.Count - 1)
             {
                 sb.Append(",");
             }
             i++;
         }
     }
     sb.Append("}");
 }
 public static string WriteFeature(IGeoJsonFeatureStyle style, IFeatureDataRecord feature)
 {
     StringBuilder sb = new StringBuilder();
     WriteFeature(sb, style, feature);
     return sb.ToString();
 }
 private static void WriteFeatureAttributes(StringBuilder sb, IGeoJsonFeatureStyle style,
                                            IFeatureDataRecord feature)
 {
     sb.Append("{");
     if (style.IncludeAttributes)
     {
         IDictionary<string, object> attributes = style.AttributeExtractionDelegate(feature);
         int i = 0;
         foreach (KeyValuePair<string, object> kvp in attributes)
         {
             sb.Append(JsonUtility.FormatJsonAttribute(kvp.Key, kvp.Value));
             if (i < attributes.Count - 1)
                 sb.Append(",");
             i++;
         }
     }
     sb.Append("}");
 }