Esempio n. 1
0
 public static IEnvelope GetEnvelopeForImage(IMap map, ICoordinate centre, double pixelWidth, double pixelHeight)
 {
     var envelope = new Envelope();
     ICoordinate size = ImageToWorld(map, pixelWidth, pixelHeight);
     envelope.SetCentre(centre, size.X, size.Y);
     return envelope;
 }
 public void Insert(Envelope envolpe, QuickInfoObject obj)
 {
     lock (m_QuadTree)
     {
         m_QuadTree.Insert(envolpe, obj);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Inserts a node into the tree using <see cref="EntryStrategy"/>
        /// </summary>
        /// <param name="key">Key for the geometry</param>
        /// <param name="region">Bounding box of the geometry to enter into the index</param>
        public virtual void Insert(UInt32 key, GisSharpBlog.NetTopologySuite.Geometries.Envelope region)
        {
            RTreeIndexEntry entry = new RTreeIndexEntry(key, region);
            Node            newSiblingFromSplit;

            EntryInsertStrategy.InsertEntry(entry, Root, _nodeSplitStrategy, Heuristic, out newSiblingFromSplit);

            // Add the newly split sibling
            if (newSiblingFromSplit is LeafNode)
            {
                if (Root is LeafNode)
                {
                    LeafNode oldRoot = Root as LeafNode;
                    Root = CreateIndexNode();
                    (Root as IndexNode).Add(oldRoot);
                }

                (Root as IndexNode).Add(newSiblingFromSplit);
                newSiblingFromSplit = null;
            }
            else if (newSiblingFromSplit is IndexNode) // Came from a root split
            {
                Node oldRoot = Root;
                Root = CreateIndexNode();
                (Root as IndexNode).Add(oldRoot);
                (Root as IndexNode).Add(newSiblingFromSplit);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="envelope"></param>
 /// <returns></returns>
 public static IEnvelope GetEnvelopeExternal(IEnvelope envelope)
 {
     // Get envelope in external coordinates
     ICoordinate min = new Coordinate(envelope.MinX, envelope.MinY);
     ICoordinate max = new Coordinate(envelope.MaxX, envelope.MaxY);
     IEnvelope bounds = new Envelope(min.X, max.X, min.Y, max.Y);
     return bounds;
 }
Esempio n. 5
0
 protected override IEnvelope AdjustBoundingBox(IEnvelope bbox, double scale, System.Drawing.Size size)
 {
     double[] points = m_transform.MathTransform.Transform(new double[] { bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY });
     IEnvelope localEnv = new Envelope(points[0], points[2], points[1], points[3]);
     localEnv = base.AdjustBoundingBox(localEnv, scale, size);
     points = m_transform.MathTransform.Inverse().Transform(new double[] { localEnv.MinX, localEnv.MinY, localEnv.MaxX, localEnv.MaxY });
     return new Envelope(points[0], points[2], points[1], points[3]);
 }
Esempio n. 6
0
 /// <summary>
 /// Returns a "safe" envelope that is guaranteed to contain the hot pixel.
 /// </summary>
 /// <returns></returns>
 public IEnvelope GetSafeEnvelope()
 {
     if (safeEnv == null)
     {
         double safeTolerance = 0.75 / scaleFactor;
         safeEnv = new Envelope(originalPt.X - safeTolerance, originalPt.X + safeTolerance,
                                originalPt.Y - safeTolerance, originalPt.Y + safeTolerance);
     }
     return safeEnv;
 }
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="querySeg"></param>
        /// <returns></returns>
        public IList Query(LineSegment querySeg)
        {
            Envelope env = new Envelope(querySeg.P0, querySeg.P1);

            LineSegmentVisitor visitor = new LineSegmentVisitor(querySeg);
            index.Query(env, visitor);
            IList itemsFound = visitor.Items;        

            return itemsFound;
        }
        public void AddObject(Region path, string layer, ToolTipInfo toolTipInfo, System.Drawing.Graphics g)
        {
            lock (m_QuadTree)
            {
                RectangleF rf = path.GetBounds(g);
                Envelope env = new Envelope(rf.Left, rf.Right, rf.Bottom, rf.Top);

                m_QuadTree.Insert(env, new QuickInfoObject(path, layer, toolTipInfo, env));
            }
        }
        public void EnvelopeChangesWhenCoverageIsCleared()
        {
            var coverage = new RegularGridCoverage(10, 10, 1, 1);
            var layer = new RegularGridCoverageLayer { Coverage = coverage };
            var envelope = new Envelope(0, 10, 0, 10);
            Assert.AreEqual(envelope, layer.Envelope);

            coverage.Clear();
            var EmptyEnvelope = new Envelope(0, 0, 0, 0);
            Assert.AreEqual(EmptyEnvelope, layer.Envelope);
        }
Esempio n. 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <param name="addEnv"></param>
        /// <returns></returns>
        public static Node CreateExpanded(Node node, IEnvelope addEnv)
        {
            IEnvelope expandEnv = new Envelope(addEnv);
            if (node != null) 
                expandEnv.ExpandToInclude(node.env);

            Node largerNode = CreateNode(expandEnv);
            if (node != null) 
                largerNode.InsertNode(node);
            return largerNode;
        }
Esempio n. 11
0
		/// <summary>
		/// Transforms a <see cref="IEnvelope" /> object.
		/// </summary>
        /// <param name="box"></param>
		/// <param name="transform"></param>
		/// <returns></returns>
		public static IEnvelope TransformBox(IEnvelope box, IMathTransform transform)
		{
			if (box == null) return null;

            double[][] corners = new double[4][];
            corners[0] = transform.Transform(ToArray(box.MinX, box.MinY)); //LL
            corners[1] = transform.Transform(ToArray(box.MaxX, box.MaxY)); //UR
            corners[2] = transform.Transform(ToArray(box.MinX, box.MaxY)); //UL
            corners[3] = transform.Transform(ToArray(box.MaxX, box.MinY)); //LR

			IEnvelope result = new Envelope();
            foreach (double[] p in corners)
				result.ExpandToInclude(p[0], p[1]);
			return result;
		}
Esempio n. 12
0
        public System.Collections.IList Query(System.Drawing.Point p)
        {
            Envelope env = new Envelope(p.X, p.X, p.Y, p.Y);
            System.Collections.IList tmpList;
            lock (m_QuadTree)
            {
                tmpList = m_QuadTree.Query(env);
            }

            List<QuickInfoObject> result = new List<QuickInfoObject>();

            foreach (QuickInfoObject qo in tmpList)
            {
                if (qo.Envelope.Contains(p.X, p.Y))
                    result.Add(qo);
            }

            return result;
        }
Esempio n. 13
0
        public void GetExtentsComputation()
        {
            DataTable source = createDataTableSource();
            DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y");

            double minX = Double.PositiveInfinity, minY = Double.PositiveInfinity, 
                maxX = Double.NegativeInfinity, maxY = Double.NegativeInfinity;

            foreach (DataRowView rowView in source.DefaultView)
            {
                if (minX > (double)rowView["x"]) minX = (double)rowView["x"];
                if (minY > (double)rowView["y"]) minY = (double)rowView["y"];
                if (maxX < (double)rowView["x"]) maxX = (double)rowView["x"];
                if (maxY < (double)rowView["y"]) maxY = (double)rowView["y"];
            }

            Envelope expectedBounds = new Envelope(minX, minY, maxX, maxY);
            IEnvelope actualBounds = provider.GetExtents();

            Assert.AreEqual(expectedBounds, actualBounds);
        }
Esempio n. 14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private Node CreateSubnode(int index)
        {
            // create a new subquad in the appropriate quadrant
            double minx = 0.0;
            double maxx = 0.0;
            double miny = 0.0;
            double maxy = 0.0;

            switch (index) 
            {
                case 0:
                    minx = env.MinX;
                    maxx = centre.X;
                    miny = env.MinY;
                    maxy = centre.Y;
                    break;

                case 1:
                    minx = centre.X;
                    maxx = env.MaxX;
                    miny = env.MinY;
                    maxy = centre.Y;
                    break;

                case 2:
                    minx = env.MinX;
                    maxx = centre.X;
                    miny = centre.Y;
                    maxy = env.MaxY;
                    break;

                case 3:
                    minx = centre.X;
                    maxx = env.MaxX;
                    miny = centre.Y;
                    maxy = env.MaxY;
                    break;

	            default:
		            break;
            }
            IEnvelope sqEnv = new Envelope(minx, maxx, miny, maxy);
            Node node = new Node(sqEnv, level - 1);
            return node;
        }
Esempio n. 15
0
	    /// <summary>
        /// Boundingbox of dataset
        /// </summary>
        /// <returns>boundingbox</returns>
        public virtual IEnvelope GetExtents()
        {
            IEnvelope envelope = new Envelope();

            for (int i = 0; i < Geometries.Count; i++)
            {
                if (!Geometries[i].IsEmpty)
                {
                    envelope.ExpandToInclude(Geometries[i].EnvelopeInternal);
                }
            }
	        
            return envelope;
        }
Esempio n. 16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        public bool IsInside(ICoordinate pt)
        {
            crossings = 0;

            // test all segments intersected by ray from pt in positive x direction
            IEnvelope rayEnv = new Envelope(Double.NegativeInfinity, Double.PositiveInfinity, pt.Y, pt.Y);
            interval.Min = pt.Y;
            interval.Max = pt.Y;
            IList segs = tree.Query(interval);

            MCSelecter mcSelecter = new MCSelecter(this, pt);
            for (IEnumerator i = segs.GetEnumerator(); i.MoveNext(); ) 
            {
                MonotoneChain mc = (MonotoneChain) i.Current;
                TestMonotoneChain(rayEnv, mcSelecter, mc);
            }

            /*
            *  p is inside if number of crossings is odd.
            */
            if ((crossings % 2) == 1) 
                return true;            
            return false;
        }
Esempio n. 17
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 protected override object ComputeBounds() 
 {
     IEnvelope bounds = null;
     for (IEnumerator i = ChildBoundables.GetEnumerator(); i.MoveNext(); ) 
     {
         IBoundable childBoundable = (IBoundable) i.Current;
         if (bounds == null) 
              bounds =  new Envelope((IEnvelope) childBoundable.Bounds);                
         else bounds.ExpandToInclude((IEnvelope) childBoundable.Bounds);
     }
     return bounds;
 }
Esempio n. 18
0
 /// <summary>
 /// Returns the BoundingBox of the dataset.
 /// </summary>
 /// <returns>BoundingBox</returns>
 public BoundingBox GetExtents()
 {
     Envelope envelope = new Envelope();
     foreach (Feature feature in features)
         envelope.ExpandToInclude(feature.Geometry.EnvelopeInternal);
     return GeometryConverter.ToSharpMapBoundingBox(envelope);
 }
Esempio n. 19
0
        /// <summary>
        /// Gets the extents of the map based on the extents of all the layers in the layers collection
        /// </summary>
        /// <returns>Full map extents</returns>
        public virtual IEnvelope GetExtents()
        {
            if (Layers == null || Layers.Count == 0)
            {
                return null;
            }

            IEnvelope envelope = new Envelope();
            for (int i = 0; i < Layers.Count; i++)
            {
                if (Layers[i].IsVisible)
                {
                    if (Layers[i].Envelope != null && !Layers[i].Envelope.IsNull)
                    {
                        envelope.ExpandToInclude(Layers[i].Envelope);
                    }
                }
            }

            return envelope;
        }
 /// <summary> 
 /// Test whether a point lies in the envelopes of both input segments.
 /// A correctly computed intersection point should return <c>true</c>
 /// for this test.
 /// Since this test is for debugging purposes only, no attempt is
 /// made to optimize the envelope test.
 /// </summary>
 /// <param name="intPt"></param>
 /// <returns><c>true</c> if the input point lies within both input segment envelopes.</returns>
 private bool IsInSegmentEnvelopes(ICoordinate intPt)
 {
     IEnvelope env0 = new Envelope(inputLines[0, 0], inputLines[0, 1]);
     IEnvelope env1 = new Envelope(inputLines[1, 0], inputLines[1, 1]);
     return env0.Contains(intPt) && env1.Contains(intPt);
 }
        /// <summary>
        /// Retrieves the contents of the specified table, and writes them to a shapefile
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public bool ExportGriddedShapefile(string tableName)
        {
            try
            {
                _log.DebugFormat("Retrieving contents of job {0}", tableName);
                //don't filter out geometries, we'll do that at the cell level
                var exportFeatures = GetShapeFeaturesToExport(tableName, false);
                if ((exportFeatures == null) || (exportFeatures.Count == 0))
                {
                    _log.ErrorFormat("Export of Job \"{0}\" failed, no features to export!", tableName);
                    return false;
                }

                ICoordinateSystem outputCrs = GeographicCoordinateSystem.WGS84;
                if (!string.IsNullOrEmpty(this.OutputProjectionFilename))
                {
                    outputCrs = Utilities.GetCoordinateSystemByWKTFile(this.OutputProjectionFilename);
                }

                //if we need to reproject:
                List<IGeometry> filteringGeoms = GetFilteringGeometries(this.ExportFilterFilename, outputCrs);

                //put everything into a basic spatial index
                Envelope env = new Envelope();
                var index = new GisSharpBlog.NetTopologySuite.Index.Strtree.STRtree();
                for (int i = 0; i < exportFeatures.Count; i++)
                {
                    Feature f = exportFeatures[i];
                    index.Insert(f.Geometry.EnvelopeInternal, f);
                    env.ExpandToInclude(f.Geometry.EnvelopeInternal);
                }
                if (IsCancelled()) { _log.Debug("Job Cancelled..."); return false; }
                index.Build();

                //adjust envelope to only scan area inside filtering geometries
                if (!string.IsNullOrEmpty(this.GridEnvelopeFilename))
                {
                    //a specified envelope file overrides the envelope of the filtering geometries
                    env = GetGridEnvelope();
                }
                else if ((filteringGeoms != null) && (filteringGeoms.Count > 0))
                {
                    //in the absence ... //TODO: finish--
                    env = new Envelope();
                    for (int i = 0; i < filteringGeoms.Count; i++)
                    {
                        env.ExpandToInclude(filteringGeoms[i].EnvelopeInternal);
                    }
                }

                //progress tracking
                DateTime start = DateTime.Now, lastCheck = DateTime.Now;
                int lastProgress = 0;

                var features = new List<Feature>(exportFeatures.Count);

                double cellWidth = GridCellWidth;
                double cellHeight = GridCellHeight;
                bool discardEmptyGridCells = !IncludeEmptyGridCells;

                int numRows = (int)Math.Ceiling(env.Height / cellHeight);
                int numCols = (int)Math.Ceiling(env.Width / cellWidth);
                int expectedCells = numRows * numCols;

                if (expectedCells > 1000000)
                {
                    _log.Warn("**********************");
                    _log.Warn("Your selected area will produce a shapefile with over a million cells, is that a good idea?");
                    _log.WarnFormat("Area of {0}, Expected Cell Count of {1}", env.Area, expectedCells);
                    _log.Warn("**********************");
                }

                DbaseFileHeader header = null;
                using (var conn = DbClient.GetConnection())
                {
                    //Dictionary<string, DataRow> shapeDict = GetShapeRowsByLOGRECNO(conn);
                    var variablesDT = DataClient.GetMagicTable(conn, DbClient, string.Format("SELECT * FROM \"{0}\" where 0 = 1 ", tableName));
                    header = ShapefileHelper.SetupHeader(variablesDT);
                }
                ShapefileHelper.AddColumn(header, "CELLID", typeof(string));
                ShapefileHelper.AddColumn(header, "GEOID", typeof(string));
                if (this.AddStrippedGEOIDcolumn)
                {
                    ShapefileHelper.AddColumn(header, "GEOID_STRP", typeof(string));
                }

                //lets not add these to the fishnet exports just yet
                //if (this.AddGeometryAttributesToOutput)
                //{
                //    ShapefileHelper.AddColumn(header, "AREA", typeof(double));
                //    ShapefileHelper.AddColumn(header, "PERIMETER", typeof(double));
                //    ShapefileHelper.AddColumn(header, "CENTROID", typeof(double));
                //}

                int cellCount = 0;
                int xidx = 0;
                for (double x = env.MinX; x < env.MaxX; x += cellWidth)
                {
                    xidx++;
                    int yidx = 0;
                    for (double y = env.MinY; y < env.MaxY; y += cellHeight)
                    {
                        yidx++;
                        cellCount++;
                        string cellID = string.Format("{0}_{1}", xidx, yidx);

                        Envelope cellEnv = new Envelope(x, x + cellWidth, y, y + cellHeight);
                        IGeometry cellCenter = new Point(cellEnv.Centre);
                        IGeometry cellGeom = Utilities.IEnvToIGeometry(cellEnv);

                        Feature found = null;
                        IList mightMatch = index.Query(cellGeom.EnvelopeInternal);
                        foreach (Feature f in mightMatch)
                        {
                            if (f.Geometry.Contains(cellCenter))
                            {
                                found = f;
                                break;
                            }
                        }

                        if ((found == null) && (discardEmptyGridCells))
                        {
                            //_log.DebugFormat("No feature found for cell {0}", cellID);
                            continue;
                        }

                        //if we have filtering geometries, skip a cell if it isn't included
                        if (!IsIncluded(cellGeom, filteringGeoms))
                        {
                            continue;
                        }

                        if ((cellCount % 1000) == 0)
                        {
                            int step = (int)((((double)cellCount) / ((double)expectedCells)) * 100.0);
                            TimeSpan elapsed = (DateTime.Now - lastCheck);
                            if ((step != lastProgress) && (elapsed.TotalSeconds > 1))
                            {
                                _log.DebugFormat("{0:###.##}% complete, {1:#0.0#} seconds, {2} built, {3} checked, {4} left",
                                   step, (DateTime.Now - start).TotalSeconds,
                                   features.Count,
                                   cellCount,
                                   expectedCells - cellCount
                                   );
                                lastCheck = DateTime.Now;
                                lastProgress = step;

                                if (IsCancelled()) { _log.Debug("Job Cancelled..."); return false; }
                            }
                        }

                        //this is a lot of work just to add an id...
                        AttributesTable attribs = new AttributesTable();
                        if (found != null)
                        {
                            //if (!found.Attributes.GetNames().Contains("GEOID"))
                            //    throw new Exception("GEOID NOT FOUND!!!!");
                            foreach (string name in found.Attributes.GetNames())
                            {
                                attribs.AddAttribute(name, found.Attributes[name]);
                            }
                            attribs.AddAttribute("CELLID", cellID);
                        }
                        else
                        {
                            foreach (var field in header.Fields)
                            {
                                attribs.AddAttribute(field.Name, null);
                            }
                            attribs["CELLID"] = cellID;
                        }

                        features.Add(new Feature(cellGeom, attribs));
                    }
                }
                _log.Debug("Done building cells, Saving Shapefile...");
                header.NumRecords = features.Count;

                if (features.Count == 0)
                {
                    _log.Error("No features found, exiting!");
                    return false;
                }

                string newShapefilename = Path.Combine(Environment.CurrentDirectory, tableName);
                if (!string.IsNullOrEmpty(OutputFolder))
                {
                    newShapefilename = Path.Combine(OutputFolder, tableName);
                }

                if (IsCancelled()) { _log.Debug("Job Cancelled..."); return false; }
                var writer = new ShapefileDataWriter(newShapefilename, ShapefileHelper.GetGeomFactory());
                writer.Header = header;
                writer.Write(features);

                if (!string.IsNullOrEmpty(this.OutputProjectionFilename))
                {
                    //Reproject everything in this file to the requested projection...
                    ShapefileHelper.MakeOutputProjFile(this.OutputProjectionFilename, newShapefilename);
                }
                else
                {
                    ShapefileHelper.MakeCensusProjFile(newShapefilename);
                }

                _log.Debug("Done! Shapefile exported successfully");
                return true;
            }
            catch (FileNotFoundException notFound)
            {
                string msg = "A needed file couldn't be found: " + notFound.FileName;
                _log.Error(msg);
                _log.Fatal("The export cannot continue.  Exiting...");
                throw new ApplicationException(msg);
            }
            catch (Exception ex)
            {
                _log.Error("Error while exporting shapefile", ex);
            }
            return false;
        }
        public Envelope GetGridEnvelope()
        {
            Envelope env = null;
            if (!string.IsNullOrEmpty(GridEnvelopeFilename))
            {
                string[] lines = File.ReadAllLines(GridEnvelopeFilename);
                foreach (string line in lines)
                {
                    if (line.StartsWith("#") || line.StartsWith("//"))
                        continue;

                    string[] chunks = line.Split(" ,:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    env = new Envelope(
                        Utilities.GetAs<double>(chunks[0], -1),     //env.MinX
                        Utilities.GetAs<double>(chunks[2], -1),  //env.MaxX
                        Utilities.GetAs<double>(chunks[1], -1),   //env.MinY
                        Utilities.GetAs<double>(chunks[3], -1)    //env.MaxY
                    );
                    break;
                }
            }

            return env;
        }
Esempio n. 23
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 protected override IEnvelope ComputeEnvelopeInternal()
 {
     IEnvelope envelope = new Envelope();
     for (int i = 0; i < geometries.Length; i++) 
         envelope.ExpandToInclude(geometries[i].EnvelopeInternal);
     return envelope;
 }
Esempio n. 24
0
        public override void Start()
        {
            IPoint interiorPoint = Factory.CreatePoint(new Coordinate(130, 150));
            IPoint exteriorPoint = Factory.CreatePoint(new Coordinate(650, 1500));
            ILineString aLine = Factory.CreateLineString(new ICoordinate[] { new Coordinate(23, 32.2), new Coordinate(10, 222) });
            ILineString anotherLine = Factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 1), new Coordinate(30, 30) });
            ILineString intersectLine = Factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 1), new Coordinate(300, 300) });            

            try
            {               
                Write(polygon.Area);
                Write(polygon.Boundary);
                Write(polygon.BoundaryDimension);
                Write(polygon.Centroid);
                Write(polygon.Coordinate);
                Write(polygon.Coordinates.Length);
                Write(polygon.Dimension);
                Write(polygon.Envelope);
                Write(polygon.EnvelopeInternal);
                Write(polygon.ExteriorRing);
                Write(polygon.InteriorPoint);
                Write(polygon.InteriorRings.Length);
                Write(polygon.IsEmpty);
                Write(polygon.IsSimple);
                Write(polygon.IsValid);
                Write(polygon.Length);
                Write(polygon.NumInteriorRings);
                Write(polygon.NumPoints);                
                if (polygon.UserData != null)
                    Write(polygon.UserData);
                else Write("UserData null");
             
                Write(polygon.Buffer(10));
                Write(polygon.Buffer(10, BufferStyle.CapButt));                
                Write(polygon.Buffer(10, BufferStyle.CapSquare));
                Write(polygon.Buffer(10, 20));
                Write(polygon.Buffer(10, 20, BufferStyle.CapButt));                
                Write(polygon.Buffer(10, 20, BufferStyle.CapSquare));
                Write(polygon.Contains(interiorPoint));
                Write(polygon.Contains(exteriorPoint));
                Write(polygon.Contains(aLine));
                Write(polygon.Contains(anotherLine));
                Write(polygon.Crosses(interiorPoint));
                Write(polygon.Crosses(exteriorPoint));
                Write(polygon.Crosses(aLine));
                Write(polygon.Crosses(anotherLine));
                Write(polygon.Difference(interiorPoint));
                Write(polygon.Difference(exteriorPoint));
                Write(polygon.Difference(aLine));
                Write(polygon.Difference(anotherLine));
                Write(polygon.Disjoint(interiorPoint));
                Write(polygon.Disjoint(exteriorPoint));
                Write(polygon.Disjoint(aLine));
                Write(polygon.Disjoint(anotherLine));
                Write(polygon.Distance(interiorPoint));
                Write(polygon.Distance(exteriorPoint));
                Write(polygon.Distance(aLine));
                Write(polygon.Distance(anotherLine));
                Write(polygon.Intersection(interiorPoint));
                Write(polygon.Intersection(exteriorPoint));
                Write(polygon.Intersection(aLine));
                Write(polygon.Intersection(anotherLine));
                Write(polygon.Intersects(interiorPoint));
                Write(polygon.Intersects(exteriorPoint));
                Write(polygon.Intersects(aLine));
                Write(polygon.Intersects(anotherLine));
                Write(polygon.IsWithinDistance(interiorPoint, 300));
                Write(polygon.IsWithinDistance(exteriorPoint, 300));
                Write(polygon.IsWithinDistance(aLine, 300));
                Write(polygon.IsWithinDistance(anotherLine, 300));
                Write(polygon.Overlaps(interiorPoint));
                Write(polygon.Overlaps(exteriorPoint));
                Write(polygon.Overlaps(aLine));
                Write(polygon.Overlaps(anotherLine));
                Write(polygon.Relate(interiorPoint));
                Write(polygon.Relate(exteriorPoint));
                Write(polygon.Relate(aLine));
                Write(polygon.Relate(anotherLine));
                Write(polygon.SymmetricDifference(interiorPoint));
                Write(polygon.SymmetricDifference(exteriorPoint));
                Write(polygon.SymmetricDifference(aLine));
                Write(polygon.SymmetricDifference(anotherLine));
                Write(polygon.ToString());
                Write(polygon.AsText());
                Write(polygon.Touches(interiorPoint));
                Write(polygon.Touches(exteriorPoint));
                Write(polygon.Touches(aLine));
                Write(polygon.Touches(anotherLine));
                Write(polygon.Union(interiorPoint));
                Write(polygon.Union(exteriorPoint));
                Write(polygon.Union(aLine));
                Write(polygon.Union(anotherLine));

                string aPoly = "POLYGON ((20 20, 100 20, 100 100, 20 100, 20 20))";
                string anotherPoly = "POLYGON ((20 20, 100 20, 100 100, 20 100, 20 20), (50 50, 60 50, 60 60, 50 60, 50 50))";                
                IGeometry geom1 = Reader.Read(aPoly);
                Write(geom1.AsText());                                
                IGeometry geom2 = Reader.Read(anotherPoly);
                Write(geom2.AsText());

                // ExpandToInclude tests
                Envelope envelope = new Envelope(0, 0, 0, 0);
                envelope.ExpandToInclude(geom1.EnvelopeInternal);
                envelope.ExpandToInclude(geom2.EnvelopeInternal);
                Write(envelope.ToString());

                // The polygon is not correctly ordered! Calling normalize we fix the problem...
                polygon.Normalize();

                byte[] bytes = polygon.AsBinary();
                IGeometry test1 = new WKBReader().Read(bytes);
                Write(test1.ToString());

                bytes = new GDBWriter().Write(polygon);
                test1 = new GDBReader().Read(bytes);
                Write(test1.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }        
Esempio n. 25
0
 /// <summary>
 /// Returns the BoundingBox of the dataset.
 /// </summary>
 /// <returns>BoundingBox</returns>
 public IEnvelope GetExtents()
 {            
     IEnvelope envelope = new Envelope();
     foreach (IFeature feature in features)
         envelope.ExpandToInclude(feature.Geometry.EnvelopeInternal);
     return envelope;
 }
Esempio n. 26
0
        public void TestStrIndex()
        {
            STRtree ndx = new STRtree();

            foreach (var v in CreateTestGeometries(1000, 0.0, 0.0, 3000.0, 3000.0))
                ndx.Insert(v.EnvelopeInternal, v);

            ndx.Build();
            IEnvelope queryExtents = new Envelope(100.0, 120.0, 100.0, 120.0);
            IList matches = ndx.Query(queryExtents);
            foreach (IGeometry list in matches)
            {
                Assert.IsTrue(list.EnvelopeInternal.Intersects(queryExtents), "a result from the index does not intersect the query bounds");
            }

        }
Esempio n. 27
0
 /// <summary>
 /// Converts the <see cref="GisSharpBlog.NetTopologySuite.Geometries.Envelope"/> instance <paramref name="envelope"/>
 /// into a correspondant <see cref="SharpMap.Geometries.BoundingBox"/>.
 /// </summary>
 public static BoundingBox ToSharpMapBoundingBox(Envelope envelope)
 {
     return new BoundingBox(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
 }
Esempio n. 28
0
        public void ChangingEnvelopeAfterMapControlIsShownWorksCorrectly()
        {
            var layer = new VectorLayer { DataSource = new DataTableFeatureProvider("POINT(1 1)") };
            var map = new Map { Layers = { layer } };

            var mapControl = new MapControl { Map = map, AllowDrop = false };

            var viewEnvelope = new Envelope(10000, 10010, 10000, 10010);

            WindowsFormsTestHelper.Show(mapControl,
                delegate
                    {
                        map.ZoomToFit(viewEnvelope);
                    });

            for (var i = 0; i < 10; i++)
            {
                Application.DoEvents();
                Thread.Sleep(100);
            }

            Assert.IsTrue(map.Envelope.Contains(viewEnvelope));

            WindowsFormsTestHelper.CloseAll();
        }
Esempio n. 29
0
		public void EnvelopeAll()
		{
			IList results = session.CreateCriteria(typeof(County))
				.SetProjection(SpatialProjections.Envelope("Boundaries"))
				.List();

			Assert.AreEqual(1, results.Count);

			IGeometry aggregated = (IGeometry)results[0];
			IEnvelope expected = new Envelope(1, 3, 0, 2);

			Assert.IsTrue(expected.Equals(aggregated.EnvelopeInternal));

		}
Esempio n. 30
0
 /// <summary>
 /// Returns the BoundingBox of the dataset.
 /// </summary>
 /// <returns>BoundingBox</returns>
 public override BoundingBox GetExtents()
 {
     var envelope = new Envelope();
     foreach (var feature in _features)
         envelope.ExpandToInclude(feature.Geometry.EnvelopeInternal);
     return envelope;
 }
Esempio n. 31
0
 /// <summary>
 /// Converts the <see cref="GisSharpBlog.NetTopologySuite.Geometries.Envelope"/> instance <paramref name="envelope"/>
 /// into a correspondant <see cref="SharpMap.Geometries.Geometry"/>.
 /// </summary>
 public static Geometries.Geometry ToSharpMapGeometry(Envelope envelope)
 {
     return ToSharpMapGeometry(new BoundingBox(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY));
 }