Nick’s Blog

Development

ORM Why?

by Nick on Mar.08, 2011, under Development

Or more precisely why not! I guess I could be counted as one of those old school developers that is now just a little stuck in his ways. I started writing software more than thirty years ago and I have seen a lot of progress in my time. There is little doubting that writing an application now is far easier than it ever was and developers now are free to focus on the problem rather than having to focus on how to solve the problem.

(continue reading…)

Leave a Comment :, , more...

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...

MVVM

by Nick on Nov.12, 2010, under Silverlight

I was recently watching a video presenting the concepts behind Microsoft’s newish programming model MVVM (Model, View, View Model). You can find the video within the article here. The reason for watching the video was that I really wanted to know what MVVM was and I really cannot complain about the content from that point of view. After watching the video I had a clearer understanding of what MVVM is. (continue reading…)

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...

Point order in spatial data (or it depends how you look at it)

by Nick on Apr.27, 2010, under GIS

I was battling with a new GIS application and started getting complaints from some people that the points were being ordered wrongly. Now I have always known that the point order in some spatial systems is important. Mostly I rely on the software between me and the storage to correct the order before saving and this time was no different. I am using the products of a relatively small Polish outfit called TatukGIS. They have made quite a nice product and are helpful when things go wrong. Their product is a viewer and middleware that allows many different spatial formats to be read or written to. You can read more on their site http://www.tatukgis.com/

Now as a use of an application I can imagine that as you draw a polygon, that represents the boundary of your garden for example, you are not concerned in which order you draw the points (clockwise or anticlockwise) but in theory it makes a difference. I’ll try and describe the reason as best as I can. There are two ways to explain it, the Oracle way that I learned a while ago and the WKT (well known text) way that I’ve only just read. To be honest both make sense but the WKT way perhaps gives a little more information than the Oracle way.

Firstly Oracle simply says that a polygon exterior is a list of points that must be filled counter clockwise. (See 2.2.4 of the spatial data types and meta data documentation.) Now I was always told that the explanation was you need to imagine yourself walking around the exterior, on your left is the interior. So, in theory, if you specify the points on the other order then everything outside your garden would become garden and only the bit inside would be not garden (nice mistake if you can get the land registry to make it). But Oracle also says that any holes in your garden must be specified clockwise. Well if you think about this for a moment (taking the classical doughnut as an example) it makes perfect sense. You walk around the outside of the doughnut anticlockwise and everything on your left is doughnut, walk around the hole clockwise and again everything on your left is doughnut.

Secondly the WKT way. WKT is a way of formatting geometries in a standard fashion that is supported by many databases and can easily be used within databases that do not natively support spatial information because the format is purely text (there is also a WKB version, a binary format, that is more efficient with the storage but is not human readable). Their documentation (section 6.1.11.1) states “The exterior boundary LinearRing defines the “top” of the surface which is the side of the surface from which the exterior boundary appears to traverse the boundary in a counter clockwise direction.”. Now if you consider this for a moment it sounds like exactly the same thing and really it is. But suppose once again that you look at your garden, draw out the points in a clockwise fashion and then hand the map to someone that does not know your garden. They might conclude that either a) you have made a mistake b) your garden is best viewed from the underside or c) your garden occupies the entire map with the exception of the small bit in the middle.

I would suggest that most people will conclude alternative a) that you have made a mistake. And it seems that this is the alternative that a large number of software packages makes (including Tatuk and GeoMedia). However they are guessing at your mistake and perhaps you really do have a massive garden. Move to three dimensional data and the difference becomes less clear. In three dimensions how can you tell  which side is the top of something, and what does top really mean? Suppose you have a drawing of cube that represents a water tank. What order would you draw the points of the bottom panel of the tank? Does the top of that panel point downwards or upwards? And what about the sides?

If you are wondering about the idea that your garden could occupy the entire globe then imagine a spherical world (a bit like earth perhaps) and draw an island round one of the poles. Now imagine how this island might look if you were to try to draw this map on a flat piece of paper. It would probably look simply like a straight line running along the top of the paper. Now how do you decide which side of the line is land and which is water? Now imagine and island that covers half of the globe. It does not matter which half, you will always need to somehow decide which is inside and which is outside.

I said earlier that I would revisit this and add some information about other file formats. The next file format up is the shapefile from ESRI. According to the ESRI definition of the shapefile (see page 9) the order of the points is opposite to that of the previous two formats that I listed. This does, of course, pose a risk for those developing tools to read from one format and write to another, and that is that they have to reverse the order with each read/write. Not that this is any reflection on ESRI, actually the shapefile format pre-dates  both of the previous two formats.

Microsoft have been fairly slow to recognise the necessity of spatial capabilities in their database but 2008 has finally seen the introduction of two new data types. Geography for storing geodetic (real world) data and geometry for storing planar data. Hopefully their time spent catching up also means they have overtaken some of the now elderly formats and engines.  For the geometry type Microsoft states that the point order does not matter. They go on here to say :-

The OGC Simple Features for SQL Specification does not dictate a ring ordering, and SQL Server does not enforce ring ordering

Which seems at odds with the earlier reference that I gave earlier stating that it does matter. However that was a draft specification so perhaps they later dropped the requirement. I can quite see how a polygon on a planar system is unambiguous but WKT is not solely used for planar systems.  Clearly a little more homework is required.

For the MS SQL Server Geography type the point order is important but the documentation I read did not say what the ordering should be. What they did say is that no geometry using a geography data type may be larger than a hemisphere and that there is effectively no such thing as an inner or and outer ring. This last point might sound like non-sense but actually it makes perfect sense.

Imagine an island that has two lakes. Now make the island so big that it covers nearly the entire planet. Does it really make sense to call one of the exteriors the outer? In other words anything that is not dry land is outside the island. Let us imagine that one of the lakes has an island of its own. And suppose the island has a school. Now you perform a query to find which schools lie on the original outer island, is the school on the island in the lake of the island included. No! Not if you are using the geometry of the main island.

But I can imagine that there are circumstances where this theoretical lack of distinction would get in the way. Suppose I want to know where all the schools are within the territory of the main island. In most other systems I’d load up my polygon, delete any interior holes and then query the database. Only under SQL Server  that will not be possible because I have no idea which is my outer, they are all outers. I might be able to iterate over the outers and find out which is the largest and delete the rest.

I am going to have to come back to this topic to make it complete for other databases and file formats.

Leave a Comment :, , , , , , , , more...

Modelio (Free Edition UML Editor)

by Nick on Nov.17, 2009, under Development

Note: Please read all the review because since writing the review I’ve been contacted by Modelio and found a workaround for the problems encountered.

This is not going to be a very in depth review. It is simply a quick summary. The first thing I want to say about Modelio is actually about me. I am not an experienced UML user. I’ve given it several goes but recently I joined a new organisation and they tend to use Visio. My problem is that Vision does not know it is creating UML and does not therefore give you the assistance that a dedicated package gives. Modelio seems to cover most of the different UML diagrams quite nicely and is easy to use. It comes in various flavours including a free edition and it was this free edition that I was using.

I managed to create quite a nice state diagram and it even supported nested state diagrams so that I was able to create sub states. I’ve now moved on to sequence diagrams and found it seems to be able to deal with them nicely and has the intelligence to be able to link to class diagrams too.

However it was around this time that I discovered the big fly in the ointment. Modelio Free does not support everything that the commercial versions support and I would not have expected it to but perhaps the biggest pain in the backside and the reason I could never recommend this software to anyone came when it was time to upgrade to a newer version. I downloaded the software, installed it, luckily selecting to leave version 1.0.1 in place, and then tried to open my model in version 1.1. It detected that I needed to migrate the model to the newer version and then declared that my license did not allow it. In other words Modelio Free is purely a trial. No serious user is going to accept that, having found a bug in the current version that is fixed in the next, they are going to have to pay for the commercial version.

So sadly I have to conclude that Modelio Free is not for the serious user, it is purely a show case/limited trial version. If you like it you will have to buy it. Don’t get me wrong, it does a nice job but this is not free like Linux or Open Source. This is trial ware and they should make that completely clear on the package.

Update

Since writing the above we first discovered that the features included the ability to upgrade and so contacted Modelio. They have been kind enough to offer me a workaround and tell me that the restriction has been dropped for future versions. This certainly changes my opinion of the software. I have no reservations about calling this free software rather than trial software because it means that as long as there are updates I will be able to move along with them. I’ll add my own findings about the software once I’ve used it a little longer and after I’ve had a chance to use the latest version because any finding that I include now may be wrong for the next release.

Leave a Comment :, , , , more...

Using OpenSource, an excuse not to offer warranty?

by Nick on Jul.03, 2009, under Development

I just watched the BBC’s Click program and the episode in question seemed to be talking (I only caught the middle of the program to be honest)  about Software Warranties and why most Software limits the liability of the Software author. Broadly speaking most people do not read the agreement and generally scroll to the bottom and then click I Agree or something similar. The reason is simple, the text is usually crammed into a tiny little space and worded so that even legal people would have a hard time working out what they are entitled to. In most cases these agreements basically remove your rights to refunds even if the software is defective and limit any liability to the cost of the software at best. (continue reading…)

Leave a Comment :, , more...

PostGIS on Ubuntu

by Nick on Jun.12, 2009, under GIS

I’d been called by an old client and they were after someone with OpenLayers experience. Now I do have some experience with OpenLayers but I decided that brushing up on the skills would do no harm. I created an application that connects to a GeoServer WMS instance on my Ubuntu machine and even managed to get the GetFeatureInfo working with a little effort (because the site and the GeoServer are in different domains it was necessary to add a proxy to the site to forward requests from the client). But what I am missing is the ability to edit data. For this to work I am going to need to turn to the WFS-T capabilities of GeoServer and that means having an editable source of data. So I’ve decided to create a PostGIS database. The rest of this article is really just about that experience and it may be a little disjointed as I’m writing it as I go along. (continue reading…)

1 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...

Wave everyone, it’s Google

by Nick on Jun.04, 2009, under Development

I’ve just watched a video by those lovely people at Google. They are now hoping to save the world from mediocre email systems and I have to say that some of what they showed really did seem quite impressive. It is really hard to describe wave and do it justice so you could just pop along to http://wave.google.com/ or you can just read what I’ve written here and hope that I have captured the essence of Wave. (continue reading…)

Leave a Comment : 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!