How to get Geometry points using Geo API

Topics: SharpMap v0.9 / v1.x
Sep 7 at 7:55 AM
Edited Sep 7 at 8:00 AM
Hi,

I have a EPSG:4326 WGS 84 Shape file and I'm able to render the map using sharpmap 1.1.
What I'm trying to achieve is when I click on a generated Polygon, the clicked polygon must be filled with a color (For identification purpose) So I'm able to get the point where I click but how to use that point and query for all the point inside that polygon so that I can color all the point which might result in coloring all the polygon.
The problem is I don't know how to do this in sharpmap version 1.1.

Previously when I was using Sharpmap 0.9 I used the below line to get all the points to color whole of the polygon.
pointArray.Collection.Add(SharpMap.Geometries.LinearRing.GeomFromWKB((byte[])Row["the_geom"]));
My Data is from Sql Spatial DB hence the Row["the_geom"].
So far I've done this.(Which highlights only the point and need to add the points into Geo API collection)
 Collection<GeoAPI.Geometries.IGeometry> geomColl = new Collection<GeoAPI.Geometries.IGeometry>();
        GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
        GeoAPI.Geometries.IGeometryFactory gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();


        SharpMap.Layers.VectorLayer mySuggestedLayer = new SharpMap.Layers.VectorLayer("Higlight");
        fillcolor = shapeFillColor;

        var factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(_SRID);
        var pointArraySubject = factory.CreateGeometryCollection(null);
        var mySubjectLayer = new SharpMap.Layers.VectorLayer("SubjectIcon");

        DataRow Row = accounts.NewRow();
        for (int i = 0; i < accounts.Rows.Count; i++)
        {
            Row = accounts.Rows[i];
            GeoAPI.Geometries.Coordinate PinPnt = new GeoAPI.Geometries.Coordinate();
            
           
            double x = Double.Parse(Row["Xcoord_geo"].ToString()); 
            double y = Double.Parse(Row["Ycoord_geo"].ToString()); 

            PinPnt.X = x;
            PinPnt.Y = y;

           //pointArray.Collection.Add(SharpMap.Geometries.LinearRing.GeomFromWKB((byte[])Row["the_geom"]));
            geomColl.Add(gf.CreatePoint(PinPnt));
          
  mySuggestedLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(geomColl);

       
        mySuggestedLayer.Style.Fill = new System.Drawing.SolidBrush(fillcolor);       
        mySuggestedLayer.Style.EnableOutline = true;
        mySuggestedLayer.SRID = _SRID;

        _map.Layers.Add(mySuggestedLayer);

        return _map;
Any help will make my day.
Coordinator
Sep 7 at 3:47 PM
var pt =...; // the point where you clicked in world coordinates

var factory = GeoAPI.GeometryServices.Instance.CreateGeometryFactory(layer.SRID);
ICanQueryLayer layer = ...; // the layer with the polygons you want to pick
var fds = new FeatureDataSet();
layer.ExecuteIntersectinQuery(factory.CreatePoint(pt), fds)
if (fds.Tables.Count > 0) then
{
    var fdt = fds.Tables[0];
    var p = new GeometryFeatureProvider(fdt);
    var highlightLayer = new SharpMap.Layers.VectorLayer("HighLight", p);
    map.Layers.Add(highlightLayer);
}

Sep 12 at 11:22 AM
Edited Sep 13 at 6:03 AM
Thanks FObermaier,
Was busy with some other stuff couldn't get time to give this a try, anyway I gave it a try and I'm not able to fill the polygon with any color only my map renders with google map as background. It just Prints the map with no color in polygons.
 var pt = PinPnt; // the point where you clicked in world coordinates  
        ICanQueryLayer layer = (ICanQueryLayer)_map.GetLayerByName("parcel"); // the layer with the polygons you want to pick
        var factory1 = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(_SRID);
        var fds = new FeatureDataSet();
        layer.ExecuteIntersectionQuery(factory.CreatePoint(pt), fds);
        if (fds.Tables.Count > 0) 
        {
            var fdt = fds.Tables[0];          

            mySuggestedLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
            mySuggestedLayer.Style.Fill = new System.Drawing.SolidBrush(fillcolor);
            mySuggestedLayer.Style.EnableOutline = true;
            mySuggestedLayer.SRID = _SRID;
            _map.Layers.Add(mySuggestedLayer);

        }
fdt -> has no table count
factory.CreatePoint(pt) -> pt has these values ({(29.864219, -95.688078, NaN)}) which is my point of-course
Any idea why?? I've a hunch that my projections formats might be wrong.
Coordinator
Sep 13 at 11:41 AM
Could you post the extent of your query layer?
Sep 15 at 11:00 AM
Edited Sep 15 at 11:04 AM
FObermaier, Please find the extents below
p.GetExtents()
{Env[1544702402546.61 : 1544778975476.93, -5405346.70633032 : 18552933.3290607]}
Area: 1834555707908307.2
Centre: {(1544740689011.77, 6573793.31136519, NaN)}
Height: 23958280.03539101
IsNull: false
MaxExtent: 76572930.327148437
MaxX: 1544778975476.9338
MaxY: 18552933.329060692
MinExtent: 23958280.03539101
MinX: 1544702402546.6067
MinY: -5405346.7063303189
Width: 76572930.327148437
Coordinator
Sep 15 at 11:19 AM
I assume p is a provider. I need layer.Envelope, sorry!
Sep 15 at 11:59 AM
layer.Envelope
{Env[326038067905.113 : 363551577477.568, -1070572.91786639 : 2056795.1738441]}
Area: 1.1731855284497333E+17
Centre: {(344794822691.34, 493111.127988858, NaN)}
Height: 3127368.0917104939
IsNull: false
MaxExtent: 37513509572.455444
MaxX: 363551577477.56812
MaxY: 2056795.1738441046
MinExtent: 3127368.0917104939
MinX: 326038067905.11267
MinY: -1070572.9178663893
Width: 37513509572.455444
Coordinator
Sep 15 at 12:33 PM
Somehow the coordinates you posted for your point clicked don't match that of the layer. Could you post the extent of the map (map.GetExtents()) and of the current viewport (map.Envelope).
Sep 15 at 1:22 PM
_map.GetExtents()
{Env[-20037508.342789 : 1544778975476.93, -20037508.342789 : 20037508.342789]}
Area: 6.1907846221249389E+19
Centre: {(772379468984.296, 0, NaN)}
Height: 40075016.685578
IsNull: false
MaxExtent: 1544799012985.2766
MaxX: 1544778975476.9338
MaxY: 20037508.342789
MinExtent: 40075016.685578
MinX: -20037508.342789
MinY: -20037508.342789
Width: 1544799012985.2766


_map.Envelope
{Env[-0.5 : 0.5, -0.5 : 0.5]}
Area: 1.0
Centre: {(0, 0, NaN)}
Height: 1.0
IsNull: false
MaxExtent: 1.0
MaxX: 0.5
MaxY: 0.5
MinExtent: 1.0
MinX: -0.5
MinY: -0.5
Width: 1.0

Coordinator
Sep 15 at 1:46 PM
Is the point (29.864219, -95.688078, NaN) actually clicked or is it some test point of yours?
To me it seems that the map has not been displayed yet.
Sep 15 at 1:52 PM
Edited Sep 15 at 1:54 PM
It's a test point and I hard code it into the map.

In the due time i tried converting the Coordinates in the geometry and I was able to Highlight the map but with one small problem
It shades some other portion rather than the one I want.

Can this be caused by improper geometry transformation issue?
Coordinator
Sep 16 at 7:04 AM
I suppose.
Sep 19 at 10:24 AM
Edited Sep 19 at 10:25 AM
FObermaier,
I got it, the geometry transformation was the issue. I tried with on the fly conversion of Geometry and it worked.
Thanks a lot Man! Cheers!
Sep 26 at 12:04 PM
RupeshMankavil wrote:
FObermaier,
I got it, the geometry transformation was the issue. I tried with on the fly conversion of Geometry and it worked.
Thanks a lot Man! Cheers!
how did you onfly geometry conversion?
Oct 21 at 4:24 AM
I have a question, how to make points on sharpMap sparkl? help me