private SqlGeometry GetNodesGeometryAggregate(IEnumerable <Noeud> nodes, double buffer) { SqlGeometry geom = SqlTypesExtensions.PointEmpty_SqlGeometry(2154); foreach (var pointGeom in nodes) { geom = geom.STUnion(buffer == 0d ? pointGeom.Geometry : pointGeom.Geometry.STBuffer(0)); } return(geom); }
public static SqlGeometry Union(float buffer, params SqlGeometry[] geoms) { int srid = geoms.First().STSrid.Value; var union = SqlTypesExtensions.PointEmpty_SqlGeometry(srid); foreach (var g in geoms) { union = union.STUnion(buffer == 0 ? g : g.STBuffer(buffer)); } return(union); }
private void Internal_SetGeometry(IEnumerable <SqlGeometryStyled> geometries) { try { if (geometries == null) { return; } geometries = geometries.Where(g => g != null && g.Geometry != null && g.Geometry.IsNull == false); _clipboard.ClipboardGeometries = geometries.Select(g => g.Geometry).ToList(); _geometriesCache = geometries; Stopwatch sw = Stopwatch.StartNew(); Stopwatch swOther = new Stopwatch(); _readyToDraw = false; ClearGDI(); if (geometries.Any() == false) { InvalidateWrapper(true, true); return; } if (geometries == null) { throw new ArgumentNullException("geometry"); } int srid = 0; if (!geometries.Select(b => b.Geometry).AreSridEqual(out srid)) { throw new ArgumentOutOfRangeException("Geometries do not have the same SRID"); } // Reprojection config // Reproject only if base layer SRID is enabled and differs from geometry SRID bool bReproject = false; int destSrid = srid; if (_IBaseLayerViewer.Enabled || bReproject) { bReproject = true; destSrid = 4326; } SqlGeometry envelope = SqlTypesExtensions.PointEmpty_SqlGeometry(destSrid); SqlGeometry envelopeNotInDefaultView = SqlTypesExtensions.PointEmpty_SqlGeometry(destSrid); Stopwatch swReproj = new Stopwatch(); bool hasGeomTaggedAsInDefaultView = false; foreach (SqlGeometryStyled geomStyled in geometries) { if (geomStyled == null || geomStyled.Geometry == null || geomStyled.Geometry.IsNull) { continue; } try { SqlGeometry geometry = geomStyled.Geometry; geometry = geometry.MakeValidIfInvalid(); if (geomStyled.Style.IsInDefaultView) { hasGeomTaggedAsInDefaultView = true; } if (bReproject) { swReproj.Start(); // Reproj vers mercator geometry = geometry.ReprojectTo(destSrid); // Reproj vers ecran geometry = SqlGeometryProjectionSink.ReprojectGeometryToMercator(geometry, 23); geometry.STSrid = destSrid; geometry = geometry.MakeValidIfInvalid(); swReproj.Stop(); } // Envelope of Union of envelopes => global BBox geometry = geometry.MakeValidIfInvalid(); if (geomStyled.Geometry.STDimension().Value == 0) { envelope = envelope.STUnion(geometry.STBuffer(bReproject ? 0.00001 : 1).STEnvelope()).STEnvelope(); } else { envelope = envelope.STUnion(geometry.STEnvelope()).STEnvelope(); } if (!geomStyled.Style.IsInDefaultView) { if (geomStyled.Geometry.STDimension().Value == 0) { // buffer the point envelopeNotInDefaultView = envelopeNotInDefaultView.STUnion(geometry.STBuffer(bReproject ? 0.00001 : 1).STEnvelope()).STEnvelope(); } else { envelopeNotInDefaultView = envelopeNotInDefaultView.STUnion(geometry.STEnvelope()).STEnvelope(); } } GraphicsPath stroke = new GraphicsPath(); GraphicsPath fill = new GraphicsPath(); List <PointF> points = new List <PointF>(); SqlGeometryGDISink.ConvertSqlGeometry(geometry, ref stroke, ref fill, ref points); AppendFilledPath(geomStyled.Style, fill); AppendStrokePath(geomStyled.Style, stroke); AppendPoints(geomStyled.Style, points); if (_showLabels) { AppendLabel(geometry, geomStyled.Label); } } catch (Exception exGeom) { swReproj.Stop(); Trace.TraceError(exGeom.Message); } } #region BBox // ------------------------------------------ // BBox // List <double> xcoords = new List <double>(); List <double> ycoords = new List <double>(); for (int i = 1; i <= envelope.STNumPoints(); i++) { xcoords.Add(envelope.STPointN(i).STX.Value); ycoords.Add(envelope.STPointN(i).STY.Value); } _geomBBox = new BoundingBox(xcoords.Min(), xcoords.Max(), ycoords.Min(), ycoords.Max()); // // BBox default view // if (hasGeomTaggedAsInDefaultView && envelopeNotInDefaultView.Points().Any()) { xcoords.Clear(); ycoords.Clear(); for (int i = 1; i <= envelopeNotInDefaultView.STNumPoints(); i++) { xcoords.Add(envelopeNotInDefaultView.STPointN(i).STX.Value); ycoords.Add(envelopeNotInDefaultView.STPointN(i).STY.Value); } _geomBBoxNotDefault = new BoundingBox(xcoords.Min(), xcoords.Max(), ycoords.Min(), ycoords.Max()); } else { _geomBBoxNotDefault = new BoundingBox(); } // // ------------------------------------------ #endregion BBox swOther.Start(); string v_geomInfo = GetGeometryInfo(geometries.Select(g => g.Geometry).ToList()); swOther.Stop(); Trace.TraceInformation("Reprojection: {0} ms", swReproj.ElapsedMilliseconds); Trace.TraceInformation("Init: {0} ms", sw.ElapsedMilliseconds); Trace.TraceInformation("Init other: {0} ms", swOther.ElapsedMilliseconds); Raise_InfoMessageSent_Init(v_geomInfo, sw.ElapsedMilliseconds); _readyToDraw = true; InvalidateWrapper(true, true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(this.GetType().Name + " Error: " + ex.Message); } }