|
William, Correct me if I am
wrong, but what you are after here is how to translate an image click into map
coordinates, right? I suspect that the actual creation of rows in SQL
Server with the x, y coordinate values is straightforward. In order to get
the map coordinate from the image click you have to do a bit of legwork since
there is no direct method call for this in mapscript (that I am aware of). You
are using mapscript_csharp, right? Here’s a bit of code that may help you
given that you have a mapextent, image width and height, and image x, y click
location: Public Shared Function ConvertImageToGeo(ByVal imgExtent As GISExtent, ByVal targExtent As GISExtent, ByVal imgPoint As GISPoint) As GISPoint '//images have 0,0 in upper left corner -
effectively switching the orientation of the axis
Dim targPoint As New GISPoint
'//make sure imgpoint is inside
imgextent
If Not imgPoint.x <= imgExtent.xMax Or Not imgPoint.x >= imgExtent.xMin Or _
Not imgPoint.y <=
imgExtent.yMax Or Not imgPoint.y >=
imgExtent.yMin Then
Return Nothing
End If
'//precentage along the x and y
axis
Dim xPercent, yPercent As Double
xPercent = (imgPoint.x - imgExtent.xMin) / imgExtent.Width
yPercent = (imgPoint.y - imgExtent.yMin) / imgExtent.Height
'//since y axisorientation is
backwards - take inverse proportion of yfactor
yPercent = 1 - yPercent
'//calculate offset
Dim targXOffset,
targYOffset As Double
targXOffset = targExtent.Width * xPercent targYOffset
= targExtent.Height * yPercent
'//calculate point
targPoint.x = targExtent.xMin + targXOffset
targPoint.y = targExtent.yMin + targYOffset
Return targPoint End Function If you are on
the client side (_javascript_) you can use this if you populate ImgW, ImgH,
MapULX and MapULY beforehand. function SetMapLoc(imgX, imgY){ var pX = imgX / ImgW; var pY = imgY / ImgH; var mapXAdd = MapW * pX; var mapYAdd = MapH * pY; MapX =
MapULX + mapXAdd; MapY =
MapULY - mapYAdd; MapX =
MapX.toPrecision(8); MapY =
MapY.toPrecision(8); } Note that
neither of these methods is very precise so if you are looking for precision,
you’ll need something more sophisticated. Hope that helps, David Lowther Coordinate
Solutions, Inc. 405.246.9396
(Voice) 405.227.0781
(Fax) www.coordinatesolutions.com From: william paul
[mailto:[EMAIL PROTECTED] Hi: I would like to create point data by clicking on the map and write the
coordinates into SQl Server 2005. It's the opposite of OVF file for creating
points from 2 columns from a DBMS (like Sql Server, MySql) When I click on the map I would like to take automatically the
coordinates and record them together with other attributes into a table (Sql
Server|) with 2 columns for x and y coordinates Is it possible to do it? I am using mapserver 4.10, dBox on IIS server and ASPX with Sql Server
2005 Thank you in advance William Sponsored Link |
