Sunday, November 4, 2012

Zoomable image with Leaflet

Last week the European Southern Observatory (ESO) published a 9 giga-pixel image cataloging 84 million stars in the Central parts of the Milky Way. They even provided this image in a zoomable format at http://www.eso.org/public/images/eso1242a/zoomable/ .

It's really cool, but I'm not particularly fond of the Flash Plugin that they've used. It's a little bit slugish, and IMHO something like Google/Bing/Leaflet could provide a much better user experience.

That said, here's what I'll do: I'll get a smaller image from ESO, split it in tile images and display it on Leaflet.

To split the image I'm going to use an utility called GDAL2Tiles. I'll show two variants of this:
  • using the command-line tool
  • using a Graphical Interface called MapTiler
If you just want to keep things simple jump right ahead to the MapTiler version. I'm also showing the command-line version because it's more productive and suitable to batching scenarios.

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, October 12, 2012

Going the micro-ORM way with Dapper

If you're a developer you've most certainly used stackoverflow (or any other of the stackexchange sites). It's the reference Q&A site out there and has got tons of helpful content and a really enthusiastic community.

One of my favorite things about Stackoverflow is that it's damn fast. The interface, although minimalistic, shows lots of information, refreshes everything on-the-fly and just feels snappy. It's public knowledge that Stackoverflow developers are obsessed with performance, and fortunately they've been more than happy to share their secrets with the community through some blog posts and videos.

To achieve the results you see today they've used many clever tricks and tweaks, but have also developed some in-house tools to overcome the performance limitations of existing technologies. In this post I'm going to look at their own ORM: Dapper, which is widely used in Stackoverflow and has been open-sourced on Github (link).

Friday, September 7, 2012

OpenStreetMaps

I haven't blogged yet specifically about OpenStreetMaps (OSM). On this post I'm going to talk a little bit about OSM and the easiness and importance of adding information.

For those that haven't heard about OSM the simplest explanation is: it's the Wikipedia for maps. A joint collaborative effort of thousands of people to create a free world map.

Recently OSM has gained a lot of traction, mostly because of the transition of some key players from other mapping technologies/data to OSM. Notable examples:
  • Foursquare
  • Apple
  • Wikipedia
  • Craigs List
I'm really glad that OSM is finally getting the exposure that it deserves, but I still feel that it's a niche thing. Everyone that likes maps obviously knows it, but it isn't as entrenched on our web culture as something like Wikipedia, and most people don't realize that there's a free mapping wiki where everyone can contribute with unique and valuable information.

Friday, August 31, 2012

Freehand drawing with Cocos2d-x and Box2d

After going on holidays and recharging my batteries I'm ready for some more blogging action.

This will be a fun one. Basically I want to:
  • Allow the user to draw a freehand shape on the screen
  • After releasing the click/gesture the shape should materialize itself into a dynamic physics body.
  • The generated bodies should be affected by gravity and will collide with each other
I'll be using cocos2d-x 2.0.1 with Box2D for the physics.

(Update: 24 March 2013: As some people were having trouble making it work I've replaced the current download with a complete XCode project using the latest Cocos2d-x version (cocos2d-x 2.1.2))

Anyway, a video is worth more than 10.000 words (heck, if a picture is worth 1000 words a video is certainly more). Here's the final effect:




Monday, July 23, 2012

C++ revisited

During my academic and professional life I've been in touch with lots of different programming languages, for example:
Pascal, C, C++, Prolog, Java, Lisp, Javascript, C#, Smalltalk, and many others.

With time I lost contact with most of them, except C#, Java and Javascript.

Recently, as explained in my blog, I began to delve onto mobile game development using C++, mostly because it's a supported language in most mobile operating (iOS, Android and Windows Phone 8), and the "El Dorado" of being able to develop once and run everywhere (sort of).

Saturday, July 14, 2012

Custom Map Tiles (Part 5 - offline maps on iOS)


In this post I'm going to create an iOS mapping application, with the added benefit of using my own map tiles served offline, i.e, deployed with the application without requiring network connection.

I'm going to use a library called MapBox-ios-sdk and the tiles will be created using TileMill and served in the .mbtiles format.

Thursday, July 5, 2012

Load-Testing ASP.NET MVC (Part 3 - JMeter (slightly more) advanced)

Part 1 - Apache Workbench
Part 2 - JMeter introduction
Part 3 - JMeter (slightly more) advanced

As promised, in this post I'm going to explain some more JMeter stuff. So, I'll show how to:
  • Submit information (HTTP POST)
  • Handle authentication
    • Particularly in the ASP.NET MVC context
  • Read information from a page and store it in a variable
    • Particularly to read the ASP.NET MVC anti-forgery token
  • Vary the posted data by reading it from a CSV file
Also, I'll include some extra elements to make the test more maintainable and professional.

So, again, lots of ground to cover so lets get started.

Thursday, June 28, 2012

Load-Testing ASP.NET MVC (Part 2 - JMeter introduction)



Although Apache Workbench provides some simple and useful metrics it's a little bit limited. In this post I'm going to talk about a much more powerful tool for load-testing: JMeter (also from the Apache Foundation).

I'll start by replicating the previous experiment that I did with Apache Worbench but using JMeter, and gradually adding more complexity to it.

Saturday, June 16, 2012

Load-Testing ASP.NET MVC (Part 1 - Apache Workbench)




Performance is a critical aspect of most applications. Everything may be pretty, really well developed, intuitive and all, but if the performance is not up to par the user experience is going to suck.


Unfortunately most of these performance problems only show themselves after some time in production, making them much more cumbersome to solve and handle.

In this post I'm going to talk about something that should, IMHO, be integrated in the development lifecycle before the application goes live: Load-tests.

Thursday, June 7, 2012

Custom Map Tiles (Part 4 - Programmatically with EF 5)


Hi,

After a pause from mapping related stuff, I couldn't resist going back for some more, especially having just downloaded Visual Studio 2012 RC1.

In this post I'm going to show how to create tiles programatically at server-side using .NET 4.5 and Entity Framework 5 RC 1.

I'll basically create an ASP.NET MVC 4.0 application which handles http tile requests, uses Entity Framework to fetch spatial data from a SQL Server database and produces a bitmap image using GDI+. Then I'll show these tiles on a Leaflet Map. This seems too much trouble for what is worth but sometimes you just need the extra control to do stuff that otherwise would be really difficult to do.

As usual I'm going to show most of the steps to get this thing working, just jumping some hoops on simpler stuff. Anyway, even if some steps seem less clear I'm including a zip file with the whole solution.


Saturday, June 2, 2012

Create 3D objects inside Cocos2D-x (Part 2 - Menus)

Part 1 - Introduction
Part 2 - Menus

In my previous post I've created a very rough experiment showing some 3D boxes on top of the default Cocos2d-X template.

In this post I'm going to create something a little bit more useful: a level selection mechanism in 3D. This demo uses some additional concepts like:
  • Texturing
  • Changing the POV (Point-of-view) based on the device accelerometer
  • Click-detection
When launching the application we have the following screen:



Saturday, May 19, 2012

Create 3D objects inside Cocos2D-x (Part 1 - Introduction)

Part 1 - Introduction
Part 2 - Menus

Cocos2D-x is, as you might infer from its name, a 2d gaming library. But, as it uses OpenGL internally to draw its stuff, we might leverage it to create some 3D objects on the mix.

In this post I'm going to show how to create a  bunch of animated 3D boxes inside a Cocos2D-X scene mixed with 2D sprites.


Although I don't recommend using Cocos2D-x for making a complete 3D game, adding some 3D objects might bring some interesting effects.

Tuesday, May 15, 2012

Video Tutorial: Scrollable layer with Parallax (LevelHelper + Cocos2d-X)

A nice game level selection mechanism, particularly for "world" selection, is a scrollable layer that snaps to specific points. Also, I want to mix this with a parallax effect.

I've created a video tutorial that shows how to create this effect using LevelHelper, SpriteHelper and Cocos2d-x. Don't mind the sucky minimalistic "art" :)

It's my first video tutorial ever, so keep your expectations moderated :P



Tuesday, May 8, 2012

Mobile game development - The road so far


I've loved gaming since my first Spectrum in 86. Although I don't play as much as before I still try to find the time for some Skyrim, Battlefield, Uncharted, etc.

Anyway, that's the "consumer" side of it. Some months ago I started to delve into game development, particularly on the mobile space. As I had just bought a Mac I decided to target iOS.

Long story short, this has been the road so far:
  • Bought a Mac
  • Enrolled in a Apple Developer Program (meaning, paid 100 usd)
  • Stared at XCode and ObjectiveC scratching my head
  • Researched
  • Tried to develop a game
  • Failed miserably
  • (paused 6 months)
  • Re-Research
  • Current Time

Saturday, April 28, 2012

Parsing UTFGrid data to polygons

I've talked previously about UTFGrid. It provides, as described by Development Seed, "a standard, scalable way of encoding data for hundreds or thousands of features alongside your map tiles".

So, to sum it up, if we have this image tile for the hexagons of one of my previous posts.


We would have a corresponding json file with this UTFGrid
         !!!!!!!!!!!!!!!!!###################$$$$$$$$$$$$$$%%
            !!!!!!!!!!!!!!!!####################$$$$$$$$$$$$$$%%
             !!!!!!!!!!!!!!######################$$$$$$$$$$$$%%%
             !!!!!!!!!!!!!!######################$$$$$$$$$$$$%%%
             &&&&&&&&&&&&&&######################''''''''''''%%%
            &&&&&&&&&&&&&&&&####################''''''''''''''%%
            &&&&&&&&&&&&&&&&&###################''''''''''''''%%
           &&&&&&&&&&&&&&&&&&##################''''''''''''''''%
           &&&&&&&&&&&&&&&&&&&#################'''''''''''''''''
          &&&&&&&&&&&&&&&&&&&&################''''''''''''''''''
         &&&&&&&&&&&&&&&&&&&&&&##############'''''''''''''''''''
         &&&&&&&&&&&&&&&&&&&&&&##############'''''''''''''''''''
        &&&&&&&&&&&&&&&&&&&&&&&&############''''''''''''''''''''
        &&&&&&&&&&&&&&&&&&&&&&&&############''''''''''''''''''''
        &&&&&&&&&&&&&&&&&&&&&&&&((((((((((((''''''''''''''''''''
         &&&&&&&&&&&&&&&&&&&&&&(((((((((((((('''''''''''''''''''
          &&&&&&&&&&&&&&&&&&&&&(((((((((((((((''''''''''''''''''
          &&&&&&&&&&&&&&&&&&&&((((((((((((((((''''''''''''''''''
           &&&&&&&&&&&&&&&&&&(((((((((((((((((('''''''''''''''')
           &&&&&&&&&&&&&&&&&&(((((((((((((((((('''''''''''''''')
            &&&&&&&&&&&&&&&&((((((((((((((((((((''''''''''''''))
             &&&&&&&&&&&&&&&((((((((((((((((((((('''''''''''''))
             &&&&&&&&&&&&&&(((((((((((((((((((((('''''''''''')))
             **&&&&&&&&&&&&(((((((((((((((((((((('''''''''''+)))
             ***************(((((((((((((((((((((+++++++++++++))
            ****************((((((((((((((((((((++++++++++++++))
           ******************((((((((((((((((((++++++++++++++++)
           ******************((((((((((((((((((++++++++++++++++)
          ********************((((((((((((((((++++++++++++++++++
          *********************(((((((((((((((++++++++++++++++++
         **********************((((((((((((((+++++++++++++++++++
         ***********************(((((((((((((+++++++++++++++++++
        ************************((((((((((((++++++++++++++++++++
        ************************(((((((((((,++++++++++++++++++++
         ***********************,,,,,,,,,,,,,+++++++++++++++++++
         **********************,,,,,,,,,,,,,,+++++++++++++++++++
          ********************,,,,,,,,,,,,,,,,++++++++++++++++++
          ********************,,,,,,,,,,,,,,,,++++++++++++++++++
           ******************,,,,,,,,,,,,,,,,,,++++++++++++++++-
            *****************,,,,,,,,,,,,,,,,,,,++++++++++++++--
            ****************,,,,,,,,,,,,,,,,,,,,++++++++++++++--
             **************,,,,,,,,,,,,,,,,,,,,,,++++++++++++---
             **************,,,,,,,,,,,,,,,,,,,,,,++++++++++++---
             ..............,,,,,,,,,,,,,,,,,,,,,,////////////---
            ................,,,,,,,,,,,,,,,,,,,,//////////////--
            .................,,,,,,,,,,,,,,,,,,,//////////////--
           ..................,,,,,,,,,,,,,,,,,,////////////////-
           ...................,,,,,,,,,,,,,,,,,/////////////////
          ....................,,,,,,,,,,,,,,,,//////////////////
         ......................,,,,,,,,,,,,,,///////////////////
         ......................,,,,,,,,,,,,,,///////////////////
        ........................,,,,,,,,,,,,////////////////////
        ........................,,,,,,,,,,,,////////////////////
        ........................000000000000////////////////////
         ......................00000000000000///////////////////
          .....................000000000000000//////////////////
          ....................0000000000000000//////////////////
           ...................00000000000000000////////////////1
           ..................000000000000000000////////////////1
            ................00000000000000000000//////////////11
            ................00000000000000000000//////////////11
             ..............0000000000000000000000////////////111
              .............0000000000000000000000//////////22111
                          00000000000000000000000222222222222111

Thursday, April 26, 2012

Entity Framework 5 and Spatial Data (Part 2 - Comparison with NHibernate Spatial)

Part 1 - Introduction
Part 2 - Comparison with NHibernate Spatial

As promised in my previous post I'm going to do a comparison between NHibernate Spatial and Entity Framework.
 
I'll start by making a pros/cons list for both libraries, but just focusing on items that may differ between them.

 NHibernate Spatial

Pros:
  • True abstraction from the database with IGeoAPI/NetTopologySuite
  • Works with .NET 3.5 and newer
Cons:
  • No longer actively developed
  • Querying with LINQ/QueryOver doesn't work in many cases
  • Some spatial operators are not implemented


Entity Framework 5 Beta 2 Spatial

Pros:
  • Setup is a breeze
  • Querying with LINQ works flawlessly.
  • Natively integrated with Entity Framework
Cons:
  • The DbGeography/DbGeometry types belong to System.Data.Spatial. Therefore, we're always tied to the database model, even if just conceptually.
  • Requires .NET 4.5 (at least in the Beta 2. I don't know if support for 4.0 is on the road)

Wednesday, April 25, 2012

Entity Framework 5 and Spatial Data (Part 1 - Introduction)


I've blogged a lot on NHibernate Spatial. Although it works nicely, it seems to have been left for dead. It no longer compiles without modifying the source code and has many missing features and bugs.

On the other hand, Entity Framework is finally receiving native Spatial Support on version 5 (it's about time). Although it still is in Beta 2, I believe it's time to check it out and to see how it fancies itself. I'm going to create an example using it against a SQL Server database.

I'm going to use the following model:
  • There are 18 districts, each defined by a polygon
  • The are about 140.000 places, each defined by a geographic point
I've already used this model on a previous blog post.

I'll create two separate projects:
  • Class library with the model
  • Console application with some spatial operations

Friday, April 20, 2012

Maps and Boardgames (Part 3 - Client Side drawing + Optimizing)


In my previous post I've shown how one may interact with an hexagon layer on top of a Leaflet map.  The particular thing in that example is that it used hexagons embedded in the server-side tile images (created using TileMill). This has some pros and cons:

Pros:
- great performance
- works on most browsers (even pre-HTML5)
- less "visual noise", as the map is rendered at the same time as the hexagons (heck, they're in the same image tiles)

Cons:
- by itself it's difficult to have client-side behavior. It's possible using something like the UTFGrid technology, but that brings some additional complexity to the table and some limitations (I've used this approach in my previous post).
- the hexagons are static. So, if for example, we want to generate the hexagons with a different size or color or change them dynamically we're kind of screwed.

In this post I'm going to try a different approach, and return to the HTML5 Canvas implementation that I've started in the first post of this series.

Saturday, April 7, 2012

Maps and Boardgames (Part 2 - Using server tiles)


In my previous post I've created an hexagon layer in client-side using HTML5 Canvas. In this post I'm going to generate the hexagons on the server and display them on a map. So, the roadmap for this post will be:
  • Generate the hexagons  in C#
  • Store them as spatial data in SQL Server 2008 using NHibernate Spatial
  • Use QuantumGIS (or any other GIS tool for that mater) to read that data and tweak it 
  • Use Tilemill to generate a layer of .mbtiles, including UTFGrid data of the hexagons
  • Extract the .mbtiles file to image files
  • Use the data on a Leaflet map.
  • Create some basic interaction on the map



If you want you can skip to the end result.

Now, we've got two options for this. We can create hexagons that overlay perfectly on top of the map, all of them having the same pixel size, or all have the same edge size in meters, regardless of where they are on the world.

Friday, March 30, 2012

Maps and Boardgames (Part 1 - Introduction)


Hi all.

If you have seen some of my posts you've probably suspected that I like spatial stuff :). I would like to make an experiment where I'm going to make some kind of boardgame engine on top of a map (probably Leaflet).

It will be a little bit useless but should be a fun exercise to apply some of the stuff that I've been talking about, like html5 canvas, tile maps, leaflet, UTFGrids, etc.

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

Sunday, March 18, 2012

Custom Map Tiles (Part 3 - TileStache)


In my previous post all the map tiles were pre-rendered and stored in the filesystem. Although that approach brings more flexibility it also has some disadvantages: storage and time.

Imagine that we want to store tiles for every zoom level covering the whole world. We would be talking probably about Pentabytes of information. Even if we just stored all the zoom levels for some countries it would be probably lots of Terabytes. Space is cheap, but we're talking about a whole new level here.

Probably even worse than the storage, it would take ages to render all of the required tiles. Without enough computational power we could be looking at months (or more) to render all the tiles. 

So, in this post, I'm going to present a realistic alternative: using a Tile Server to generate and cache map tiles on-the-fly. I'm going to use TileStache for this.

Tuesday, March 13, 2012

Custom Map Tiles (Part 2 - TileMill)


In my previous post I've shown a really simple way of overlaying custom map tiles on top of Bing Maps using MapCruncher.

One of the problems with that approach is that it only works for raster files. If one needs to do more complex stuff like creating tiles with data from shapefiles, kml or databases then a different method/tool must be used.

We have three challenges here:
  1. How do we create a raster map representation of our raw data?
  2. How do we split that image in tiles?
  3. How do we serve those tiles to the map client (like Bing/Google maps)? 
I'm going to use a tool that simplifies this process without sacrificing any quality on the process: TileMill. TileMill is, like stated in their homepage, "an application for making beautiful maps". It uses a Mapnik core to render the maps, and provides a very simple UI and a CSS-like language to style them. I could praise the application a little bit more but I prefer to show you.

Wednesday, March 7, 2012

Custom Map Tiles (Part 1 - MapCruncher)



When drawing overlays on top of a map one can choose between two different methods: custom map tiles or using the map API.

On this series of posts I'm going to show what are custom map tiles, how overlaying them compares to using the map API in client-side and finally how to interact with the tiles.

Friday, March 2, 2012

Sunday, February 26, 2012

ASP.NET MVC 4 (Part 1 - Web API)

Since ASP.NET MVC was launched it became my favorite framework for developing web applications. I believe that Microsoft pushed all the right buttons with it: really well conceived, extensible, modular and testable, with every iteration of ASP.NET MVC bringing lots of great improvements.

Now, MVC4 is in beta, and as before many new features have been introduced. The official whitepaper with the release notes may be read here.

One of the new features is called "ASP.NET Web API" which is, according to Microsoft description:

"(...) a new framework for creating HTTP services that can reach a broad range of clients including browsers and mobile devices. ASP.NET Web API is also an ideal platform for building RESTful services."

Thursday, February 23, 2012

Visual Studio 11, .NET 4.5 and MVC 4

I've been wanting to try out the Developer preview of Visual Studio 11 and .NET 4.5 for some time. The problem is that new technologies and products have appeared/evolved at an incredible pace and it's difficult to keep oneself on track with all the novelties, specially when time has become such a limited asset.

Anyway, today is the day. It's .NET day! I've already installed:

  • Visual Studio 11
  • .NET 4.5 (C# 5.0)
  • MVC 4.0
  • SQL Server 2012
There are so many new things to try out, but I'm particularly interested in :

  • the new C# 5.0 features, like the "async" and "await" keywords
  • native WebSockets in .NET
  • The WebAPI in MVC 4.0
  • The new Mobile stuff of MVC 4.0
  • Asynchronous controllers with Tasks and the async keyword (hell yeah)
  • The new spatial features of SQL Server 2012
  • The new distribution features, like packaging javascript files, minification(?), MSBuild 4.5 features
  • etc, etc, etc
I'm not sure where to start, but I would like to do something that I haven't done before: besides doing regular tutorial posts I would like to accompany them with video-tutorials. Not exactly sure what will come out of this but, in the worst case scenario, should be a fun experiment :)

Anyway, gotta hurry, Visual Studio 11 expires in 127 days :P


Tuesday, February 21, 2012

Leaflet and HTML5

When one thinks of web map platforms Google Maps and Bing Maps are the two obvious choices. They're both free as long as you comply with some ground rules (i.e, terms of use) and don't exceed their usage limit. Unfortunately many applications can't adhere to those restrictions, leaving them with two options: purchase a commercial license or use a free alternative.

The most common free alternative is, without a doubt, OpenLayers. It provides an incredibly complete API (much more than Google and Bing) and integration with varied data sources (see examples here). The problem with OpenLayers, in my opinion, is it complexity. I'm also not particularly fond of the map control itself, but that's probably just personal taste.

Anyway, recently appeared a new kid on the block: Leaflet. It is a free lightweight mapping solution that provides a rich and extensible API, very much focused on HTML5. Also, it includes something that a lot of developers are asking for in Bing Maps V7: a client-side canvas layer. In this post I'm going to show how it works and develop a working prototype.

Update (21/01/2013): I've added a working example here

Saturday, February 18, 2012

Bing Maps and HTML5 (Part 4 - Final optimization)


In Part 3 of this "Bing Maps and HTML5" series I optimized the drawing of the Canvas quite a bit. The time taken to draw the canvas with 140.000 points was cut from 800ms to 75ms.

Anyway, and as I said previously, my target was (and is) the 40ms mark (1000/25) for a full canvas render with all the points. Why? Because I want the data to be continuously drawn while the map is zoomed/panned, and it has to be fluid.
After profiling my code, the bottleneck is still the function where wgs84 coordinates are converted to pixel coordinates.

Update 26/07/2012: I've added a working example here. I've also added a zip file with the project here.
I modified the demo so that the data is not fetched from a node.js but from a separate js file instead.

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.

Sunday, February 12, 2012

KineticJS

HTML5 Canvas is freaking awesome and, although HTML5 has many improvements over HTML4, Canvas is probably one of the strongest and my personal favorite.

One of the things that I like about Canvas is that it provides a really nice low-level API, allowing for a great degree of control over the drawing. The problem is that, without using an external library, some simple tasks are a little bit cumbersome and hard to maintain.

For example, let's assume we want to create a simple page like:
          • Two boxes, one red and one blue.
          • Each box will show an alert when clicked upon.








Saturday, February 11, 2012

Bing Maps and HTML5 (Part 3 - Optimizing)


In my previous post I've created an example where about 140.000 points are retrieved from a MongoDB database and drawn on top of a Bing Maps using Html5 canvas.

If you recall, it took about 800+ ms to create and display the canvas above the map when all the points were visible. For the current scenario it's acceptable, as the drawing only occurs after the view changed event has ended. The problem is that I would like to have the drawing being continuously drawn during the view changed events. So, and for the motion to be fluid, each canvas image has to be drawn in less than 40 ms(1000/25).
Obviously it depends on the CPU of the client machine. My laptop is pretty average, so it will be a realistic benchmark. I'll post my attempts to achieve the 40ms target on my computer, starting with the current post, where I try to solve the most problematic operation.

Friday, February 10, 2012

Bing Maps and HTML5 (Part 2 - Canvas)


In my previous post I've created a very simple example of a map that fetches a bunch of coordinates from a Node.js server using HTML5 websockets.

As promised, I'm going to extend that example so that much more coordinates are fetched and displayed.

I've used a MongoDB database and loaded it with most of the Portuguese localities, on a total of 142912 coordinates. As one may suspect, it's impossible to draw so many pushpins on a map without resorting to some type of clustering technique. I won't do the clustering (at least on this post), and will instead draw them using one of the HTML5 goodies: the Canvas element.


Wednesday, February 8, 2012

Bing Maps and HTML5 (Part 1 - Basic)


I've just finished a working prototype of a very basic interaction between Bing Maps and Node.js.

The idea is very simple: open a map, fetch a bunch of coordinates (using websockets) and display them.

The end result should be something like this:



Sunday, February 5, 2012

Fast display of data in a map

Recently the HTML5 bandwagon has gained a lot more traction, and I'm going to develop a prototype for a map with fast client-side drawing on top of it, using some of the goodies that HTML5 provides us.

The basic idea is:
  • Bing Maps or Leaflet mapping-wise
  • Html5 Canvas to draw the data (points, heatmaps, grids, whatever)
  • Html5 websockets to fetch the data
  • NodeJS to create an ultra-fast server to return the data to the client (without HTTP protocol overhead, just a plain TCP socket).
  • MongoDB to handle the data.
Also, I want to be able to handle thousands (if not millions) of coordinates at once.


Saturday, February 4, 2012

Fibonacci

Picking up on my previous post, I mentioned that many attempts were required to get an available url for my blog. While I was searching for the "perfect name" I even attempted some urls just for fun. One of those attempts was:

http://0112358.blogspot.com

As some of the more astute may recognize it's the beginning of the Fibonacci number sequence. It's sort of original but I wasn't too surprised that it was unavailable. Anyway, and as it is an infinite sequence, I tried to find the point on which I had an available url.

My attempts:

http://011235.blogspot.com -> Sorry, this blog address is not available
http://0112358.blogspot.com -> Sorry, this blog address is not available
http://011235813.blogspot.com -> Sorry, this blog address is not available
http://0112358132134.blogspot.com -> Sorry, this blog address is not available
http://011235813213455.blogspot.com -> Sorry, this blog address is not available
http://01123581321345589.blogspot.com -> Sorry, this blog address is not available
http://01123581321345589144.blogspot.com -> Sorry, this blog address is not available
http://01123581321345589144233.blogspot.com -> This blog address is available.

So, only after the 13th fibonacci number (233) you have an available blog.... :|

So, if anyone wants a really nice and user-friendly URL for your blog, here it is :D

Friday, February 3, 2012

Yay

Well, after 20 or so "Sorry, this blog address is not available" here I am: my first "real" blog. I'll be writing my thoughts on technology, particularly on programming.

I've been developing sofware for some time now, but I'm also interested in 2d/3d design, music software and games. I work mostly with Microsoft technologies but I have an open-mind to try out new stuff.

Somethings on which I would like to blog about:

.NET in general

Databases
- ORMs
- NoSQL - MongoDB
- Tuning

GIS / Mapping
- Bing Maps, Leaflet, OpenLayers
- NHibernate Spatial

NodeJS

Game development for iOS
- Cocos2D & Box2D


Well, you get the picture.

This isn't in any way a roadmap or anything, just mumbling (hence the title) :)