Map coordinates not corresponding

Topics: General Topics, SharpMap v0.9 / v1.x
Jul 13, 2010 at 12:49 AM

Hello, I'm just learning SharpMap, so, I hope I'm not doing a dumb question.

I have two maps, one for a country, and one for a region in that country.  When I click the region map, I want to mark the clicked point in the country map.  To get this point, I translate image coordinates of the clicked point to world coordinates, using the region map.  Then I use these world coordinates and the country map object to translate them to image coordinates and mark the point, but they don't correspond.

       void pb_RegionMap_MouseClick(object sender, MouseEventArgs e)
        {
            SharpMap.Geometries.Point l_objRegionPoint = i_objRegionMap.ImageToWorld(new PointF((float)e.X, (float)e.Y));
            PointF l_objPoint;

            l_objPoint = i_objCountryMap.WorldToImage(l_objRegionPoint);
            pb_PointImage.Location = new Point((int)l_objPoint.X, (int)_objPoint.Y);

        }

I know the shp files are correct, because I can use the region shape file as a layer in the country map and it is rendered ok (I use it in a different color and looks OK).

How can I achieve this?

 

Thanks.

FMarin.

Coordinator
Jul 14, 2010 at 12:48 PM

hello fmarin,

are the coordinates way off or just a bit?

could you post the content of the respective prj files and the extents of the layers and the sizes of the maps?

cheers

FObermaier

Developer
Jul 14, 2010 at 4:03 PM

Hi,

What is the parent of the point image? If it is not the map but the form there will be a discrepancy of the top left of the map is not equal to the top left of the form.

Paul

Jul 14, 2010 at 5:45 PM

First of all, thank you for the replies.

Paul: You are right, I totally forgot that.  I moved the image to the tabPage where the map is and now it is working.

Thanks a lot!!!