private static bool IsSameStructureCollection(GeometryCollection g1, GeometryCollection g2)
 {
     if (g1.NumGeometries != g2.NumGeometries)
         return false;
     for (int i = 0; i < g1.NumGeometries; i++)
     {
         if (!IsSameStructure(g1.GetGeometryN(i), g2.GetGeometryN(i)))
             return false;
     }
     return true;
 }
Пример #2
0
 public static List<IGeometry> Project(List<IGeometry> toList, ProjectionInfo pStart, ProjectionInfo pEnd)
 {
     var geometryCollection = new GeometryCollection(toList.ToArray());
     var collection = geometryCollection.ToDotSpatial();
     var featureSet = new FeatureSet();
     foreach (var geo in collection.Geometries)
     {
         featureSet.Features.Add(geo);
     }
     featureSet.Projection = pStart;
     featureSet.Reproject(pEnd);
     var dotSpatialProjectedGeos =
         featureSet.Features.Select(x => x.BasicGeometry as DotSpatial.Topology.IGeometry).ToList();
     var result =
         dotSpatialProjectedGeos.Select(
             dotSpatialProjectedGeo => GeometryConverter.ToGeoAPI((dotSpatialProjectedGeo)))
             .ToList();
     return result;
 }
Пример #3
0
        /// <summary>
        /// Creates a <see cref="GeometryCollection"/> using the next token in the stream.
        /// </summary>
        /// <param name="tokenizer"> Tokenizer over a stream of text in Well-known Text
        /// format. The next tokens must form a GeometryCollection Text.</param>
        /// <returns>
        /// A <see cref="GeometryCollection"/> specified by the next token in the stream.</returns>
        private static GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer)
        {
            var arrgeometries = new List<IGeometry>();

            string nextToken = GetNextEmptyOrOpener(tokenizer);
            if (nextToken.Equals("EMPTY"))
                return new GeometryCollection(arrgeometries.ToArray());

            arrgeometries.Add(ReadGeometryTaggedText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken.Equals(","))
            {
                arrgeometries.Add(ReadGeometryTaggedText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }

            GeometryCollection geometries = new GeometryCollection(arrgeometries.ToArray());
            return geometries;
        }
Пример #4
0
        private static Geometry CreateWKBGeometryCollection(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // The next byte in the array tells the number of geometries in this collection.
            int numGeometries = (int) ReadUInt32(reader, byteOrder);

            var geometriesArray = new IGeometry[numGeometries];
            // Loop on the number of geometries.
            for (int i = 0; i < numGeometries; i++)
            {
                // Call the main create function with the next geometry.
                geometriesArray[i] = Parse(reader);
            }

            // Create a new array for the geometries.
            GeometryCollection geometries = new GeometryCollection(geometriesArray);

            // Create and return the next geometry.
            return geometries;
        }
        public void TestWriteSimpleShapeFile()
        {
            var p1 = Factory.CreatePoint(new Coordinate(100, 100));
            var p2 = Factory.CreatePoint(new Coordinate(200, 200));

            var coll = new GeometryCollection(new IGeometry[] { p1, p2, });
            ShapefileWriter.WriteGeometryCollection(@"test_arcview", coll);

            // Not read by ArcView!!!
        }
Пример #6
0
 public static string ToGeoJson(IEnumerable<System.Data.Entity.Spatial.DbGeometry> dbGeometrys,
     ProjectionInfo pStart)
 {
     var pEnd = Definitions.WorldProjection;
     var enumerable = dbGeometrys as IList<System.Data.Entity.Spatial.DbGeometry> ?? dbGeometrys.ToList();
     var reader = new WKTReader();
     var geometryCollection =
         new GeometryCollection(
             enumerable.Select(x => GeometryHelper.Project(x.MakeValid(), pStart, pEnd))
                 .Select(dbGeometry => reader.Read(dbGeometry.WellKnownValue.WellKnownText))
                 .ToArray());
     var geoJsonWriter = new GeoJsonWriter();
     return geoJsonWriter.Write(geometryCollection);
 }
Пример #7
0
        /// <summary>
        ///     geoJson should be feature or featureCollection. convert and project geoJson to DbGeometry
        /// </summary>
        /// <param name="geoJson"></param>
        /// <param name="pStart"></param>
        /// <param name="pEnd"></param>
        /// <returns></returns>
        public static System.Data.Entity.Spatial.DbGeometry ToGeometry(string geoJson, ProjectionInfo pStart,
            ProjectionInfo pEnd)
        {
            var featureCollection = FeatureCollection(geoJson);

            var geometries =
                Project(featureCollection.Features.Select(feature => feature.Geometry).ToList(), pStart, pEnd);

            var wktWriter = new WKTWriter();
            var geoemetryColleciton = new GeometryCollection(geometries.ToArray());

            var wkt = wktWriter.Write(geoemetryColleciton);
            var geometry = System.Data.Entity.Spatial.DbGeometry.FromText(wkt);
            return geometry;
        }
Пример #8
0
        /// <summary>
        /// Writes a geometrycollection.
        /// </summary>
        /// <param name="gc">The geometrycollection to be written.</param>
        /// <param name="bWriter">Stream to write to.</param>
        /// <param name="byteorder">Byte order</param>
        private static void WriteGeometryCollection(GeometryCollection gc, BinaryWriter bWriter, WkbByteOrder byteorder)
        {
            //Get the number of geometries in this geometrycollection.
            int numGeometries = gc.NumGeometries;

            //Write the number of geometries.
            WriteUInt32((uint) numGeometries, bWriter, byteorder);

            //Loop on the number of geometries.
            for (int i = 0; i < numGeometries; i++)
            {
                //Write the byte-order format of the following geometry.
                bWriter.Write((byte) byteorder);
                //Write the type of each geometry.
                WriteType(gc[i] as Geometry, bWriter, byteorder);
                //Write each geometry.
                WriteGeometry(gc[i] as Geometry, bWriter, byteorder);
            }
        }
Пример #9
0
 /// <summary>
 /// Converts a GeometryCollection to &lt;GeometryCollection Text &gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="geometryCollection">The GeometryCollection to process.</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendGeometryCollectionText(GeometryCollection geometryCollection, StringWriter writer)
 {
     if (geometryCollection == null || geometryCollection.IsEmpty)
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (int i = 0; i < geometryCollection.Length; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendGeometryTaggedText(geometryCollection[i], writer);
         }
         writer.Write(")");
     }
 }
Пример #10
0
 /// <summary>
 /// Converts a GeometryCollection to &lt;GeometryCollection Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="geometryCollection">The GeometryCollection to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendGeometryCollectionTaggedText(GeometryCollection geometryCollection,
                                                        StringWriter writer)
 {
     writer.Write("GEOMETRYCOLLECTION ");
     AppendGeometryCollectionText(geometryCollection, writer);
 }