Purpose of MsSqlSpatial and NTS

Topics: Data Access, General Topics, SharpMap Project, SharpMap v0.9 / v1.x, Web Controls
Jul 14, 2008 at 10:15 AM
this is neoo.I am a new user of sharpmap.I can show shapefile through sharpmap v0.9 in the web.But I am unable to discover some fiture of sharpmap like select a specific polygon by click.
I read some discussion here,they talk about NTS,MsSqlSpatial but I dont understand.Can any body explain what is the purpose of  NTS,MsSqlSpatial and how they interact with sharpmap? how can I learn  and use NTS,MsSqlSpatial ?
Jul 14, 2008 at 10:44 AM
Hi neoo,
NTS is a library which allows editing, manipulation, comparison, aggregation and such on geometries,
ProjNet is a library which allows reprojection of geometries from one coordinate system into another
MsSqlSpatial is a Database extension for SqlServer 2005 (+) which puts NTS and ProjNet functionality into the database.
There is a provider for MsSqlSpatial which allows it to be used as a datasource for sharpmap (an alternative to a shapefile for instance)
There is also a converter which converts between Sharpmap native geometries and NTS native geometries.
hth jd
Jul 15, 2008 at 11:13 AM
thanks JohnDiss
Thank you for your reply.
You write " MsSqlSpatial is a Database extension for SqlServer 2005 (+)",So how can convert My shapfile to MsSqlSpatial or is this requir to fulfil my requirment.
My requirment is to select a specific polygon by click.To do my requirment, do I need NTS and MsSqlSpatil ?

Jul 15, 2008 at 11:44 AM
Edited Jul 15, 2008 at 12:40 PM
Hi neoo, there is a command line utility as part of mssqlspatial which will import a shapefile into sql server for you. If you run the app (msscmd.exe) it will display a list of options.

As regards your requirement - you need a function which will find geometries near the point you have clicked. There are examples in the forum. In short you need to:

obtain the image coordinate of your click.

buffer the coordinate by a tolerance (+/- 2px for example) value giving you the min and max coordinates of a box (NB. You can get away without this step for polygons - but it is useful if you wish to do similar with points and lines).

convert these to real world coordinates and then into an Extents giving you a box in real world coordinates.

execute an intersection test between your extent and the geometries. In MsSqlSpatial you can use ST.FilterQuery to accomplish this - it will return a dataset of all polygons in the table which intersect your 'query' box.

hth jd

Note: unless you need geometry transformations, stick with the trunk version as install and uninstall is easier. Transformation are part of the trunk version, but may be incorrect for complex transforms.