Example #1
0
    protected override SharpMap.Rendering.Label CreateLabel(SharpMap.Geometries.Geometry feature, string text, float rotation, SharpMap.Styles.LabelStyle style, Map map, System.Drawing.Graphics g)
    {
      //System.Drawing.SizeF size = g.MeasureString(text, style.Font);

      System.Drawing.PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid());
      //position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
      //position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
      if (position.X /*- size.Width*/ > map.Size.Width || position.X /*+ size.Width */< 0 ||
        position.Y /*- size.Height*/ > map.Size.Height || position.Y /*+ size.Height*/ < 0)
        return null;
      else
      {
        SharpMap.Rendering.Label lbl;

        if (!style.CollisionDetection)
          lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, null, style);
        else
        {
          //Collision detection is enabled so we need to measure the size of the string
          lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority,
            new SharpMap.Rendering.LabelBox(position.X /*- size.Width * 0.5f*/ - style.CollisionBuffer.Width, position.Y + /*size.Height * 0.5f*/ + style.CollisionBuffer.Height,
            /*size.Width +*/ 2f * style.CollisionBuffer.Width, /*size.Height +*/ style.CollisionBuffer.Height * 2f), style);
        }
        if (feature.GetType() == typeof(SharpMap.Geometries.LineString))
        {
          SharpMap.Geometries.LineString line = feature as SharpMap.Geometries.LineString;
          if (line.Length / map.PixelSize > 40/*size.Width*/) //Only label feature if it is long enough
            CalculateLabelOnLinestring(line, ref lbl, map);
          else
            return null;
        }

        return lbl;
      }
    }
 public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, SharpMap.Data.FeatureDataSet ds)
 {
     ExecuteIntersectionQuery(geom.GetBoundingBox(), ds);
 }
Example #3
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'.
        /// Please note that the ShapeFile provider currently doesn't fully support geometryintersection
        /// and thus only BoundingBox/BoundingBox querying are performed. The results are NOT
        /// guaranteed to lie withing 'geom'.
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, FeatureDataSet ds)
        {
            SharpMap.Data.FeatureDataTable dt = (SharpMap.Data.FeatureDataTable)dbaseFile.NewTable;
            SharpMap.Geometries.BoundingBox bbox = geom.GetBoundingBox();
            //Get candidates by intersecting the spatial index tree
            List<uint> objectlist = tree.Search(bbox);

            if (objectlist.Count == 0)
                return;

            for (int j = 0; j < objectlist.Count; j++)
            {
                for (uint i = (uint)dt.Rows.Count - 1; i >= 0; i--)
                {
                    FeatureDataRow fdr = GetFeature(objectlist[j],dt);
                    if (fdr.Geometry != null)
                        if (fdr.Geometry.GetBoundingBox().Intersects(bbox))
                        //replace above line with this:  if(fdr.Geometry.Intersects(bbox))  when relation model is complete
                            if (FilterDelegate == null || FilterDelegate(fdr))
                                dt.AddRow(fdr);
                }
            }
            ds.Tables.Add(dt);
        }
Example #4
0
        public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, double amountGrow, ref double DistanceToSelected)
        {
            SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
            SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
            DataSource.ExecuteIntersectionQuery(bbox, ds);
            System.Data.DataTable tbl = ds.Tables[0] as SharpMap.Data.FeatureDataTable;
            GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
            GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());
            if (tbl.Rows.Count == 0)
                return null;

            double distance = point.Distance(reader.Read((tbl.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry.ToString()));
            SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows[0] as SharpMap.Data.FeatureDataRow;

            if (tbl.Rows.Count > 1)
                for (int i = 1; i < tbl.Rows.Count; i++)
                {
                    GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry.ToString());
                    if (point.Distance(line) < distance)
                    {
                        distance = point.Distance(line);
                        selectedFeature = tbl.Rows[i] as SharpMap.Data.FeatureDataRow;
                    }
                }
            DistanceToSelected = distance;
            return selectedFeature;
        }
Example #5
0
 public SharpMap.Data.FeatureDataSet SelectElements(SharpMap.Geometries.Point point, string layername)
 {
   return SelectElements(point.GetBoundingBox(), layername);
 }
Example #6
0
    public void ZoomToElement(SharpMap.Geometries.Geometry Element)
    {
      if (Element == null)
        return;

      SharpMap.Geometries.Point point = Element.GetBoundingBox().GetCentroid().AsPoint();
      if ((point.X == 0.0) && (point.Y == 0.0))
        return;
      _BaseMap.Center = Element.GetBoundingBox().GetCentroid();
      _RealTimeMap.ZoomToBox(_BaseMap.Envelope);
      _MapArea = _BaseMap.Envelope;
      BaseMapRedrawn = false;
      OverviewMapRedrawn = false;
      RealTimeMapRedrawn = false;
      RefreshViews();
    }