Nick’s Blog

Tag: GIS

Inserting a geometry into a SQL Server 2008 Database

by Nick on Dec.09, 2010, under GIS

I’m not sure why but it seems that there is a lack of documentation surrounding how you get spatial data into and out of a SQL server 2008 database. Some people resort to using WKT (well known text) others serialise to a binary format. I was not happy with either approach, I mean inserting data into a database should be relatively straightforward.

So before we go anything further. Here is the code I created to create a SQL Server 2008 point geometry and insert it into a table with two columns. The first column was an auto increment ID and is not shown, the second is called LOCATION and is defined as a Geometry as far as SQL Server is concerned.

private void Add(Point point)
{
   SqlGeometryBuilder builder = new SqlGeometryBuilder();
   builder.SetSrid(900913);
   builder.BeginGeometry(OpenGisGeometryType.Point);
   builder.BeginFigure(point.X, point.Y);
   builder.EndFigure();
   builder.EndGeometry();
   SqlGeometry geom = builder.ConstructedGeometry;
   SqlCommand cmd = _dbConnection.CreateCommand();
   cmd.CommandText = "INSERT INTO READING (LOCATION) VALUES (@geometry)";
   SqlParameter param = cmd.Parameters.AddWithValue("geometry", geom);
   param.UdtTypeName = "Geometry";
   cmd.ExecuteNonQuery();
}

The Point type that is passed in is my own and simply contains an X and a Y. The types SqlGeometryBuilder and SqlGeometry are defined in Microsoft.SqlServer.Types which requires that you install Microsoft SQL Server System CLR Types which you can find via http://www.microsoft.com/downloads/en/details.aspx?FamilyID=228de03f-3b5a-428a-923f-58a033d316e1&DisplayLang=en. Something that fooled me was that after installing this I expected the reference to be in the GAC. Well it isn’t, or at least it isn’t on my machine and instead I had to browse to C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll. 

The lines to note are

   SqlParameter param = cmd.Parameters.AddWithValue(“geometry”, geom);
   param.UdtTypeName = “Geometry”;

The first adds the Geometry object as a parameter and the second tells SQL Server what kind of UDT (or user defined type) we are using. Strange that it was not possible to devise a way to make Geometry and Geography fully fledged types but the extra work is very little.

Leave a Comment :, , , more...

Tatuk GIS

by Nick on Sep.25, 2010, under GIS

I’ve been using Tatuks DK.Net version 9 for about a year now. The choice to use Tatuk was not mine but rather it appears to have been financially driven by predecessors and I have to say price performance is very good. You pay only for a license for each developer and are then free to distribute the applications to as many users or customers as you want.

The DK includes a control for the display of maps within the application that is capable of displaying data from a wide range of spatial data sources (http://www.tatukgis.com/Products/InternetServer/Features.aspx) including all the major ones such as ESRI, Oracle Spatial, WKB, WKT, and most common raster formats. The control also supports printing templates allowing the map to be printed with a border and text adornments.

Along side the visible mapping capabilities, the DK also includes an amount of spatial processing capabilities. You can filter spatially or create buffer zones and much more. It all adds up to making creating a map with Tatuk quite easy.

There are, however, some downsides. While the DK is very fast with shapefiles this appears only to be because it loads vast amounts (or possibly all) the data into memory. This really does give us a very fast map but as we add data from other sources the memory usage builds up and the map slows down. Performance with Oracle Spatial is currently proving a headache for us as clients are insisting on adding every layer available to them and making map rendering times to say the least sluggish.

To add to this problem we find that the DK cannot share layer information between map instances. We wanted to build an application with maps in several places. The main screen contains a map and the fact that startup time is not quick is not really a problem, however we would have liked to have had auxiliary maps on various other forms in the application. However those instances cannot be made to share information with the main map and so have the same memory usage and startup time.

Another weakness of the DK appears to be that it only operates on the GUI thread. I did some tests early on with running the DK on another thread and I was able to get it to do some work but not by doing anything that was Tatuk approved. The reason I wanted DK to run on another thread was simply that every time the map renders the entire GUI stalls. I had hoped that the slower layers could be rendered on a separate thread while the faster raster layers gave context to the user.

In all I think Tatuk is a great product and for the price you’ll find it hard to do better. The guys at Tatuk are supremely helpful and willing to look into most problems. However you can try to push it too far and perhaps our product is doing that.

Leave a Comment :, more...

More progress on SilverMap

by Nick on Jun.07, 2009, under GeoServer, GIS, Silverlight

SilverMap is not really aimed at becoming a real product, it is simply to allow me to get real experience of developing a Silverlight application that makes use of my GIS skills. I had already managed to create a viewer that pans around OpenStreetMaps. I added a few markers that also support clustering for when markers are too close to each other and now I support WMS.

Now some of you not from the GIS world may be wondering what WMS is. It stands for Web Map Service and essentially allows you to form a request for a bitmap (usually) of the area you are interested in. You then display this bitmap in your browser and, voila, you have a basic map. Alternatively you can render the bitmap over (or under) other data and then things start to become more interesting because a source of data from one server can be combined with another server and the user gets the impression of a single map with all the content they want.

Something that hindered me was that I wanted to use a public WMS server so that I did not have to find a way to make one work for me on my own computer at home. There are two drawbacks here, firstly I could not find one that was fast enough and secondly even if I had found such a server I would probably not have been able to make it work with Silverlight as Microsoft has created a mechanism within Silverlight that prevents an application running from one domain from calling a server in another domain. There is a workaround that involves putting a file on the server telling the Silverlight application that it is OK to make the cross domain call but the chances of me getting some public WMS server to place this file in their server is probably nill.

The rest of this blog covers the creation of my own WMS server and the problems I encountered. (continue reading…)

3 Comments :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Founder chanel replica founded the Chanel brand in Paris, France in 1913. replica gucci wide range of products, including clothing, jewelry and accessories, cosmetics, perfume, each product is famous, especially her hermes replica and replica bags . Chanel is a famous brand with more than 80 years of experience. Chanel fashion always has elegant, simple and exquisite style. She is good at breaking through the tradition. She successfully pushed the fake bags of “Five Flowers” to simple and comfortable in the 1940s. This is perhaps the earliest modern casual wear.