/// <summary>
 /// 
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 private static IGeometry CheckShapefile(string fileName)
 {
     //int count = 0;
     var geoms = new List<IGeometry>();
     using (ShapefileDataReader reader = new ShapefileDataReader(fileName, GeometryFactory.Floating))
     {                
         while (reader.Read())
         {
             IGeometry current = reader.Geometry;
             if (!current.IsValid)
             {
                 Debug.WriteLine("Imvalid geometry found: " + current);
                 continue;
             }
             geoms.Add(current);
             //if (result == null)
             //    result = current;
             //else result = result.Union(current);
             //Debug.WriteLine("Iteration => " + ++count);
         }
     }
     IGeometry result = UnaryUnionOp.Union(geoms);
     var write = new WKTWriter {Formatted = true, MaxCoordinatesPerLine = 3, Tab = 2};
     Debug.WriteLine("Operation result: " + write.Write(result));
     return result;
 }
        private IGeometry BuildGrid()
        {
            var lines = new ILineString[_numLines * 2];
            int index = 0;

            for (int i = 0; i < _numLines; i++)
            {
                Coordinate p0 = new Coordinate(GetRandOrdinate(), 0);
                Coordinate p1 = new Coordinate(GetRandOrdinate(), GridWidth);
                ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 });
                lines[index++] = line;
            }

            for (int i = 0; i < _numLines; i++)
            {
                Coordinate p0 = new Coordinate(0, GetRandOrdinate());
                Coordinate p1 = new Coordinate(GridWidth, GetRandOrdinate());
                ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 });
                lines[index++] = line;
            }

            IMultiLineString ml = _geomFactory.CreateMultiLineString(lines);
            _grid = ml.Buffer(_lineWidth);
            var wktWriter = new WKTWriter(2) {Formatted = true, MaxCoordinatesPerLine = 6};
            if (Verbose)
                Console.WriteLine(wktWriter.Write(_grid));
            return _grid;

        }
Exemplo n.º 3
0
 public static System.Data.Entity.Spatial.DbGeometry UnionAggregate(
     IEnumerable<System.Data.Entity.Spatial.DbGeometry> dbGeometrys)
 {
     var wktReader = new WKTReader();
     var geometries = dbGeometrys.Select(x => wktReader.Read(x.WellKnownValue.WellKnownText)).ToArray();
     var collection = new GeometryCollection(geometries);
     var wktWriter = new WKTWriter();
     return System.Data.Entity.Spatial.DbGeometry.FromText(wktWriter.Write(collection));
 }
Exemplo n.º 4
0
 public static System.Data.Entity.Spatial.DbGeometry Project(System.Data.Entity.Spatial.DbGeometry source,
     ProjectionInfo pStart, ProjectionInfo pEnd)
 {
     var wkt = source.WellKnownValue.WellKnownText;
     var wktReader = new WKTReader();
     var geometry = wktReader.Read(wkt);
     var featureSet = new FeatureSet();
     featureSet.Features.Add(geometry.ToDotSpatial());
     featureSet.Projection = pStart;
     featureSet.Reproject(pEnd);
     var projected =
         (featureSet.Features.First().BasicGeometry as IGeometry).ToGeoAPI();
     var wktWriter = new WKTWriter();
     var projectedWkt = wktWriter.Write(projected);
     return System.Data.Entity.Spatial.DbGeometry.FromText(projectedWkt);
 }
Exemplo n.º 5
0
 public void FixtureSetup()
 {
     writer = new WKTWriter();
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WKTTest"/> class.
 /// </summary>
 public WKTTest() : base()
 {            
     writer = new WKTWriter();
 }
 private void printFormatted(IGeometry geom)
 {
     WKTWriter writer = new WKTWriter();
     Console.WriteLine(writer.WriteFormatted(geom));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Converts a Geometry to its Well-known Text representation.
 /// </summary>
 /// <param name="geometry">A geometry to process.</param>
 /// <param name="writer">Stream to write out the geometry's text representation.</param>
 /// <remarks>
 /// Geometry is written to the output stream as &lt;Geometry Tagged Text&gt; string (see the OpenGIS
 /// Simple Features Specification).
 /// </remarks>
 public static void Write(IGeometry geometry, StringWriter writer)
 {
     WKTWriter wkt = new WKTWriter();
     wkt.Write(geometry, writer);
     //AppendGeometryTaggedText(geometry, writer);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Returns the Well-known Text representation of this <c>Geometry</c>.
 /// For a definition of the Well-known Text format, see the OpenGIS Simple
 /// Features Specification.
 /// </summary>
 /// <returns>
 /// The Well-known Text representation of this <c>Geometry</c>.
 /// </returns>
 public string ToText()
 {
     var writer = new WKTWriter(3);
     return writer.Write(this);
 }
Exemplo n.º 11
0
 public void SetUp()
 {
     _originalWktWriter = new WKTWriter();
     _sdeStWktWriter = new SdeStWktWriter();
 }