/// <summary> /// Calculates the union of the current box and the given coordinate. /// </summary> public virtual IEnvelope Union(ICoordinate coord) { IEnvelope env = (IEnvelope)this.Clone(); env.ExpandToInclude(coord); return(env); }
private void RefreshValuesAndCoordinates() { log.Debug("Cashing values ..."); valuesVariable = GetCoverageValuesVariable(); if (valuesVariable.NoDataValues.Count > 0) { noDataValue = valuesVariable.NoDataValues[0]; } valueIndices = GetIndicesWhereValuesExist().ToList(); // cache indices values = GetVariableValuesByIndex(valuesVariable, valueIndices).ToList(); // cache values log.Debug("Caching coordinates ..."); envelope = new Envelope(); x = GetVariableValuesByIndex(coverage.X, valueIndices).ToList(); y = GetVariableValuesByIndex(coverage.Y, valueIndices).ToList(); for (var i = 0; i < x.Count; i++) { envelope.ExpandToInclude(x[i], y[i]); } log.Debug("Creating default theme ..."); GenerateTheme(); }
/// <summary> /// Returns a new envelope that is a copy of this envelope, but modified /// to include the specified coordinate. /// </summary> public static IEnvelope Union(this IEnvelope self, Coordinate coord) { IEnvelope env = self.Copy(); env.ExpandToInclude(coord); return(env); }
/// <summary> /// Calculates the union of the current box and the given coordinate. /// </summary> IEnvelope IEnvelope.Union(ICoordinate coord) { IEnvelope env = Copy(); env.ExpandToInclude(coord); return(env); }
/// <summary> /// Boundingbox of dataset /// </summary> /// <returns>boundingbox</returns> public IEnvelope GetExtents() { if (_Geometries.Count == 0) { return(null); } IEnvelope box = null; // _Geometries[0].GetBoundingBox(); for (int i = 0; i < _Geometries.Count; i++) { if (!_Geometries[i].IsEmpty) { if (box == null) { box = _Geometries[i].EnvelopeInternal; } else { box.ExpandToInclude(_Geometries[i].EnvelopeInternal); } } } return(box); }
/// <summary> /// Expands the given Envelope to include the coordinates in the sequence. /// Allows implementing classes to optimize access to coordinate values. /// </summary> /// <param name="env">The envelope to expand.</param> /// <returns>A reference to the expanded envelope.</returns> public IEnvelope ExpandEnvelope(IEnvelope env) { for (int i = 0; i < coordinates.Length; i++) { env.ExpandToInclude(coordinates[i]); } return(env); }
/// <summary> /// Expands the given Envelope to include the coordinates in the sequence. /// Allows implementing classes to optimize access to coordinate values. /// </summary> /// <param name="env">The envelope to expand.</param> /// <returns>A reference to the expanded envelope.</returns> public override IEnvelope ExpandEnvelope(IEnvelope env) { for (int i = 0; i < coords.Length; i += dimension) { env.ExpandToInclude(coords[i], coords[i + 1]); } return(env); }
private void AutoGenerateWFSBounds_Click(object sender, EventArgs e) { try { m_isUpdating = true; System.Globalization.CultureInfo ic = System.Globalization.CultureInfo.InvariantCulture; IFeatureSource fs = (IFeatureSource)m_connection.ResourceService.GetResource(m_resourceId); bool failures = false; IEnvelope env = null; var desc = m_connection.FeatureService.DescribeFeatureSource(fs.ResourceID); foreach (ClassDefinition scm in desc.AllClasses) { foreach (var col in scm.Properties) { if (col.Type == OSGeo.MapGuide.MaestroAPI.Schema.PropertyDefinitionType.Geometry || col.Type == OSGeo.MapGuide.MaestroAPI.Schema.PropertyDefinitionType.Raster) { try { IEnvelope re = m_connection.FeatureService.GetSpatialExtent(fs.ResourceID, scm.Name, col.Name, true); if (env == null) { env = re; } else { env.ExpandToInclude(re); } } catch { failures = true; } } } } if (env == null) { throw new Exception(failures ? Strings.ResProp_NoSpatialDataWithFailuresError : Strings.ResProp_NoSpatialDataError); } m_isUpdating = false; WFSBounds.Text = "<Bounds west=\"" + env.MinX.ToString(ic) + "\" east=\"" + env.MaxX.ToString(ic) + "\" south=\"" + env.MinY.ToString(ic) + "\" north=\"" + env.MaxY.ToString(ic) + "\" />"; //NOXLATE } catch (Exception ex) { string msg = NestedExceptionMessageProcessor.GetFullMessage(ex); MessageBox.Show(this, string.Format(Strings.ResProp_WFSBoundsReadError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { m_isUpdating = false; } }
/// <summary> /// Expands the given Envelope to include the coordinates in the sequence. /// Does not modify the original envelope, but rather returns a copy of the /// original envelope after being modified. /// </summary> /// <param name="env">The envelope use as the starting point for expansion. This envelope will not be modified.</param> /// <returns>The newly created envelope that is the expanded version of the original.</returns> public IEnvelope ExpandEnvelope(IEnvelope env) { IEnvelope temp = env.Copy(); foreach (Coordinate coord in _internalList) { temp.ExpandToInclude(coord); } return(temp); }
/// <summary> /// Expands the given Envelope to include the coordinates in the sequence. /// Does not modify the original envelope, but rather returns a copy of the /// original envelope after being modified. /// </summary> /// <param name="env">The envelope use as the starting point for expansion. This envelope will not be modified.</param> /// <returns>The newly created envelope that is the expanded version of the original.</returns> public virtual IEnvelope ExpandEnvelope(IEnvelope env) { IEnvelope cEnv = env.Copy(); for (int i = 0; i < _coordinates.Length; i++) { cEnv.ExpandToInclude(_coordinates[i]); } return(cEnv); }
/// <summary> /// Calculates the combined extent that encompasses all the raster images in this document. /// </summary> /// <returns></returns> public IEnvelope CalculateExtent() { IEnvelope env = null; foreach (var loc in _items.Values) { if (env == null) { env = loc.CalculateExtents(); } else { env.ExpandToInclude(loc.CalculateExtents()); } } return(env); }
/// <summary> /// Calculates the combined extents of all the raster images in this specified location /// </summary> /// <returns>null if there are no raster images. Otherwise returns the combined extent</returns> public IEnvelope CalculateExtents() { IEnvelope env = null; foreach (var item in _items.Values) { if (env == null) { env = ObjectFactory.CreateEnvelope(item.MinX, item.MinY, item.MaxX, item.MaxY); } else { env.ExpandToInclude(ObjectFactory.CreateEnvelope(item.MinX, item.MinY, item.MaxX, item.MaxY)); } } return(env); }
/// <summary> /// Transforms a <see cref="GisSharpBlog.NetTopologySuite.Geometries.Envelope"/>. /// </summary> /// <param name="box">BoundingBox to transform</param> /// <param name="transform">Math Transform</param> /// <returns>Transformed object</returns> public static GeoAPI.Geometries.IEnvelope TransformBox(GeoAPI.Geometries.IEnvelope box, IMathTransform transform) { if (box == null) { return(null); } double[][] corners = new double[4][]; corners[0] = transform.Transform(ToLightStruct(box.MinX, box.MinY)); //LL corners[1] = transform.Transform(ToLightStruct(box.MaxX, box.MaxY)); //UR corners[2] = transform.Transform(ToLightStruct(box.MinX, box.MaxY)); //UL corners[3] = transform.Transform(ToLightStruct(box.MaxX, box.MinY)); //LR IEnvelope result = GeometryFactory.CreateEnvelope(); foreach (double[] p in corners) { result.ExpandToInclude(p[0], p[1]); } return(result); }
/// <summary> /// Calculates the union of the current box and the given box. /// </summary> public static IEnvelope Union(this IEnvelope self, IEnvelope box) { if (box == null) { return(self.Copy()); } if (box.IsNull) { return(self.Copy()); } if (self == null) { return(box.Copy()); } if (self.IsNull) { return(box.Copy()); } IEnvelope result = self.Copy(); result.ExpandToInclude(box); return(result); }
protected IEnvelope envelope; // TODO: make it private, currently used to improve performance and still remain robust (clear envelope on change) public virtual IEnvelope GetExtents() { // TODO: cache envelope, but make sure it is updated after changes occur if (Features == null || Features.Count == 0) { return(null); } if (this.envelope != null) { return(this.envelope); } IEnvelope envelope = new Envelope(); foreach (IFeature feature in Features) { if (feature.Geometry == null) { continue; } // HACK: probably we should not use EnvelopeInternal here but Envelope if (envelope.IsNull) { envelope = (IEnvelope)feature.Geometry.EnvelopeInternal.Clone(); } envelope.ExpandToInclude(feature.Geometry.EnvelopeInternal); } this.envelope = envelope; return(envelope); }
private static void AddFeature(ICollection <IFeature> features, List <ICoordinate> coordinates, IEnvelope envelope) { IGeometry geometry = null; if (coordinates.Count == 1) { var coordinate = coordinates.First(); geometry = new LineString(new[] { coordinate, coordinate }); } else if (coordinates.Count > 1) { geometry = new LineString(coordinates.ToArray()); } if (geometry == null) { return; } envelope.ExpandToInclude(geometry.EnvelopeInternal); features.Add(new Feature { Geometry = geometry }); }
/// <summary> /// Creates a node and either splits the objects recursively into sub-nodes, or stores them at the node depending on the heuristics. /// Tree is built top->down /// </summary> /// <param name="objList">Geometries to index</param> /// <param name="depth">Current depth of tree</param> /// <param name="heurdata">Heuristics data</param> public QuadTree(List <BoxObjects> objList, uint depth, Heuristic heurdata) { _Depth = depth; _box = objList[0].box; for (int i = 0; i < objList.Count; i++) { _box.ExpandToInclude(objList[i].box); } // test our build heuristic - if passes, make children if (depth < heurdata.maxdepth && objList.Count > heurdata.mintricnt && (objList.Count > heurdata.tartricnt || ErrorMetric(_box) > heurdata.minerror)) { List <BoxObjects>[] objBuckets = new List <BoxObjects> [2]; // buckets of geometries objBuckets[0] = new List <BoxObjects>(); objBuckets[1] = new List <BoxObjects>(); string longaxis = LongestAxis(_box); // longest axis double geoavg = 0; // geometric average - midpoint of ALL the objects // go through all bbox and calculate the average of the midpoints double frac = 1.0f / objList.Count; for (int i = 0; i < objList.Count; i++) { if (longaxis == "X") { geoavg += objList[i].box.Centre.X * frac; } else { geoavg += objList[i].box.Centre.Y * frac; } } // // bucket bbox based on their midpoint's side of the geo average in the longest axis for (int i = 0; i < objList.Count; i++) { if (longaxis == "X") { objBuckets[geoavg > objList[i].box.Centre.X ? 1 : 0].Add(objList[i]); } else { objBuckets[geoavg > objList[i].box.Centre.Y ? 1 : 0].Add(objList[i]); } } //If objects couldn't be splitted, just store them at the leaf //TODO: Try splitting on another axis if (objBuckets[0].Count == 0 || objBuckets[1].Count == 0) { _child0 = null; _child1 = null; // copy object list _objList = objList; } else { // create new children using the buckets _child0 = new QuadTree(objBuckets[0], depth + 1, heurdata); _child1 = new QuadTree(objBuckets[1], depth + 1, heurdata); } } else { // otherwise the build heuristic failed, this is // set the first child to null (identifies a leaf) _child0 = null; _child1 = null; // copy object list _objList = objList; } }
/// <summary> /// Expands the given Envelope to include the coordinates in the sequence. /// Allows implementing classes to optimize access to coordinate values. /// </summary> /// <param name="env">The envelope to expand.</param> /// <returns>A reference to the expanded envelope.</returns> public override IEnvelope ExpandEnvelope(IEnvelope env) { for (int i = 0; i < coords.Length; i += dimension ) env.ExpandToInclude(coords[i], coords[i + 1]); return env; }
/// <summary> /// Creates a node and either splits the objects recursively into sub-nodes, or stores them at the node depending on the heuristics. /// Tree is built top->down /// </summary> /// <param name="objList">Geometries to index</param> /// <param name="depth">Current depth of tree</param> /// <param name="heurdata">Heuristics data</param> public QuadTreeOld(List<BoxObjects> objList, uint depth, Heuristic heurdata) { _Depth = depth; _box = new Envelope(objList[0].box); for (int i = 0; i < objList.Count;i++ ) _box.ExpandToInclude(objList[i].box); // test our build heuristic - if passes, make children if (depth < heurdata.maxdepth && objList.Count > heurdata.mintricnt && (objList.Count > heurdata.tartricnt || ErrorMetric(_box) > heurdata.minerror)) { List<BoxObjects>[] objBuckets = new List<BoxObjects>[2]; // buckets of geometries objBuckets[0] = new List<BoxObjects>(); objBuckets[1] = new List<BoxObjects>(); string longaxis = LongestAxis(_box); // longest axis double geoavg = 0; // geometric average - midpoint of ALL the objects // go through all bbox and calculate the average of the midpoints double frac = 1.0f / objList.Count; for (int i = 0; i < objList.Count;i++ ) { if (longaxis=="X") geoavg += objList[i].box.Centre.X * frac; else geoavg += objList[i].box.Centre.Y * frac; } // // bucket bbox based on their midpoint's side of the geo average in the longest axis for (int i = 0; i < objList.Count;i++ ) { if(longaxis=="X") objBuckets[geoavg > objList[i].box.Centre.X ? 1 : 0].Add(objList[i]); else objBuckets[geoavg > objList[i].box.Centre.Y ? 1 : 0].Add(objList[i]); } //If objects couldn't be splitted, just store them at the leaf //TODO: Try splitting on another axis if (objBuckets[0].Count == 0 || objBuckets[1].Count == 0) { _child0 = null; _child1 = null; // copy object list _objList = objList; } else { // create new children using the buckets _child0 = new QuadTreeOld(objBuckets[0], depth + 1, heurdata); _child1 = new QuadTreeOld(objBuckets[1], depth + 1, heurdata); } } else { // otherwise the build heuristic failed, this is // set the first child to null (identifies a leaf) _child0 = null; _child1 = null; // copy object list _objList = objList; } }
/// <summary> /// Expands the given Envelope to include the coordinates in the sequence. /// Allows implementing classes to optimize access to coordinate values. /// </summary> /// <param name="env">The envelope to expand.</param> /// <returns>A reference to the expanded envelope.</returns> public IEnvelope ExpandEnvelope(IEnvelope env) { for (int i = 0; i < coordinates.Length; i++ ) env.ExpandToInclude(coordinates[i]); return env; }
/// <summary> /// /// </summary> /// <param name="ring"></param> public void Add(ILinearRing ring) { rings.Add(ring); totalEnv.ExpandToInclude(ring.EnvelopeInternal); }