Return Value

Apr 14, 2010 at 9:00 AM

Hello!

I would like return the value of an VectorLayer, I use this prog:

<code>
public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer,double amountGrow)
{
SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
DataTable tbl = ds.Tables0 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.Rows0 as SharpMap.Data.FeatureDataRow).Geometry.ToString()));
SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows0 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.Rowsi as SharpMap.Data.FeatureDataRow).Geometry.ToString());
if (point.Distance(line) < distance)
{
distance = point.Distance(line);
selectedFeature = tbl.Rowsi as SharpMap.Data.FeatureDataRow;
}
}
return selectedFeature;
}
</code>
pos: position click mouse on map
layer: layer click
amountGrow: area need grow surround pos. ( about 50 pixel)
Now You can draw geometry in datarow :
<code>
SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, layerSelected,50);
//create the selected layer SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geomertry);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map" </code>
My problem are when I click on the layer, "selectedFeature" return null
I use SharMapCF.

Anyone help me?? Please

PS: Sorry for my english.

Apr 14, 2010 at 1:17 PM

I have a new problem...

 

At the ligne 'double distance = point.Distance(reader.Read((tbl.Rows0 as SharpMap.Data.FeatureDataRow).Geometry.ToString()));' I have an error 'NotImplementedException was unhandled'...

Please help me!

Coordinator
Apr 19, 2010 at 8:09 AM

if you encounter an error, posting the full stack helps locate the error.

FObermaier

Apr 19, 2010 at 8:22 AM

Hello FObermaier,

I use the SharpMapCF.dll, I try the SharpMap.dll and this function work fine.

I juste change the .dll in my project and it's work... The problem is that I must make in Windows Embedded CE...

PS: Sorry for my english

Developer
Apr 20, 2010 at 8:12 PM

I was wondering, where did you get the BruTileCF.dll version from?

Paul

Apr 21, 2010 at 7:17 AM

Hello paudendulk,

 

I don't have a file BruTileCF.dll, but where is this file?

Developer
Apr 21, 2010 at 12:05 PM

oh, sorry, I meant: where did you get SharpMapCF.dll?

 

Apr 21, 2010 at 12:28 PM

I get SharpMapCF.dll in 'reference'.

I develop on Compact Framework v2 in Windows Embedded 6... And I have a new error :

'Method not found: ChangeType System.Convert.'

at the ligne : 'object obj = reader.Read(pose);'

this is my prog:

public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer, double amountGrow)
        {
            SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
            SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

            layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
            DataTable tbl = ds.Tables[0] as SharpMap.Data.FeatureDataTable;

            GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
            string pose = Sharp.GeometryToWKT2.WritePoint(pos);
            object obj = reader.Read(pose); //!!!erreur ici!!!
            GeoAPI.Geometries.IGeometry point = obj as GeoAPI.Geometries.IGeometry;

            if (tbl.Rows.Count == 0)
                return null;

            object o = reader.Read(Sharp.GeometryToWKT2.Write(((tbl.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry) as SharpMap.Geometries.IGeometry));
            double distance = point.Distance(o as GeoAPI.Geometries.IGeometry);

            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(Sharp.GeometryToWKT2.Write((tbl.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry));
                    if (point.Distance(line) < distance)
                    {
                        distance = point.Distance(line);
                        selectedFeature = tbl.Rows[i] as SharpMap.Data.FeatureDataRow;
                    }
                }
            return selectedFeature;
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            MaLayer.DataSource.Open();
            SharpMap.Data.FeatureDataRow rowSelected = FindGeoNearPoint(myMap.ImageToWorld(new Point(e.X, e.Y)), MaLayer, 50);
            if (rowSelected != null)
            {
                statusBar1.Text = rowSelected.ItemArray[1].ToString() + " Unité dose ";
            }
            MaLayer.DataSource.Close();
        }

Coordinator
Apr 21, 2010 at 5:32 PM

Paul, I think the source is here: http://code.google.com/p/sharpmapcf/source/browse/#svn/branches/0.9

Hth FObermaier

Apr 22, 2010 at 9:04 AM

Hello!

 

My application run good, but in Compact Framewok it's very very long...