Showing posts with label NHibernate. Show all posts
Showing posts with label NHibernate. Show all posts

Wednesday, October 24, 2012

NHibernate Spatial (Part 5 - NHibernate 3.3.1+)


NHibernate Spatial is sort-of moribund, which is rather unfortunate because it's a really great project with lots of potential. Anyway, not conformed with it I decided to put the sucker onto Github to create an unofficial working version of it.

Fortunately some lads had the same idea avoiding me the extra-work. Unfortunately their projects don't have that much activity and most don't seem to really work. Anyway, in the spirit of GitHub and collaboration I decided to fork one of these to try my luck. Also, if time permits, I'll try to maintain it for future NHibernate releases.

I've forked the following project: https://github.com/suryapratap/Nhibernate.Spatial. The author already set it up nicely, making the following changes to the broken nhcontrib version:
  • Fixed compilation errors
  • Used NuGet for some references
  • Upgraded the projects from VS2008 to VS2010
So, props for suryapratap for providing a much nicer starting point. My own fork is at: https://github.com/pmcxs/Nhibernate.Spatial where I'm going to update this library.

Friday, March 23, 2012

NHibernate Spatial (Part 4 - Querying)


In my previous NH Spatial post I've shown a concrete end-to-end example of how to use NHibernate Spatial on an ASP.NET MVC project.
Anyway, there's still much to be said about using this library and I've received some hits on my blog from people who were searching for how to do specific spatial operations with NH Spatial. So, this blog post will be pretty much practical, showing some spatial queries using NH Spatial on SQL Server 2008 R2, taking into account some variables in the process:
  • Geography (always assuming SRID 4326)  and Geometry data types
  • HQL and LINQ
  • NHibernate version

Saturday, February 18, 2012

NHibernate Spatial (Part 3)


This is the third part of a series of posts regarding a simple example using NHibernate Spatial.


Actually, the title is kind of misleading as this post is just the wrap-up of the previous one, and I will not do much more regarding NHibernate Spatial (at least on this post). I'll just do the web page for the user interaction.

As I said, I'll create a simple map that, when clicked on  a specific point, paints the district that contains it. Not particularly useful but should be easy enough to understand and adapt to a more realistic scenario.

Thursday, February 16, 2012

NHibernate Spatial (Part 2)


Well, now that we've got a working NHibernate Spatial dll (from my previous post) let's put it to some good use.

I want to create a relatively simple example that uses spatial data with NH Spatial. For this tutorial I'm going to create a SQL Server 2008 database table with all of the Portuguese districts. Each district will have it's area stored in the database.


 There should be 18 polygons which fill the entire country and do not overlap (obviously).



I'll display a Bing map on a webpage. When the user clicks on a point of the map the district that contains that point will be fetched and the polygon will be displayed on the map with a certain color.



All of the queries will be done with NHibernate using NHibernate Spatial for the GIS operations, in this case the intersection between the click-coordinate and the corresponding district area.






Tuesday, February 14, 2012

NHibernate Spatial (Part 1 - Introduction)


NHibernate is a nice, tested and mature ORM. I've used it extensively since version 1.2 and it just keeps getting better and better.
It obviously provides many challenges, most of them regarding it's learning curve and some limitations, like handling spatial data at the database

Nowadays several Databases provide spatial extensions. The most notorious are probably PostGIS, Oracle Spatial and more recently SQL Server 2008. NHibernate does not natively handle this type of data but fortunately there's a library that fills this gap quite nicely: NHibernate Spatial Extensions.

In this post (or series of posts) I'm going to do a complete tutorial on setting up a SQL Server 2008 R2 database with spatial columns, mapping the tables to domain objects using NHibernate Spatial and querying them with HQL and QueryOver.