<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://nhforge.org/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Sample usage</title><link>http://nhforge.org/wikis/spatial/sample-usage.aspx</link><description>Learn about this NHibernate extension allowing you to easily handle geographic data in a standard way.</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Sample usage</title><link>http://nhforge.org/wikis/spatial/sample-usage.aspx</link><pubDate>Wed, 01 Oct 2008 17:37:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:39</guid><dc:creator>Ricardo Stuven</dc:creator><comments>http://nhforge.org/wikis/spatial/sample-usage/comments.aspx</comments><description>Current revision posted to Spatial by Ricardo Stuven on 01/10/2008 02:37:00 p.m.&lt;br /&gt;
&lt;h2&gt;Sample usage&lt;/h2&gt;
&lt;h4 class="wikidoc"&gt;Find a country by coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = session.CreateCriteria(typeof(Country))
    .Add(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
    .UniqueResult() as Country;&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = Country.FindOne(
    SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Find all the towns in a bounding box, except the one located at some coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;IList towns = session.CreateCriteria(typeof(Town))
    .Add(SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)))
    .Add(Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))))
    .List();&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Town[] towns = Town.FindAll(
    SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)),
    Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The previous example just shows how to combine a spatial criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Contains&lt;/span&gt;&lt;/span&gt;) with a normal criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Not&lt;/span&gt;&lt;/span&gt;), but in this case we could use simply &lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Disjoint&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h4&gt;Get states boundaries grouping counties by state: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;ProjectionQuery&amp;lt;County&amp;gt; query = new ProjectionQuery&amp;lt;County&amp;gt;(
    Projections.ProjectionList()
        .Add(Projections.GroupProperty(&amp;quot;State&amp;quot;))
        .Add(SpatialProjections.Union(&amp;quot;Boundaries&amp;quot;))
    );
IList&amp;lt;object[]&amp;gt; stateBoundaries= query.Execute();&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For people with a GIS backgroud, the &amp;quot;projection&amp;quot; term could be confusing. In this context, it has nothing to do with cartographic projections. It&amp;#39;s rather a term borrowed from &lt;a class="externalLink" href="http://en.wikipedia.org/wiki/Projection_(relational_algebra)"&gt;&lt;span style="color:#3e62a6;"&gt;relational algebra&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Create a new vehicle GPS position: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;public void TrackVehicule(Vehicle vehicule, double longitude, double latitude, DateTime when)
{
    Tracking tracking = new Tracking();
    tracking.Vehicle = vehicle;
    tracking.Position = new Point(longitude, latitude);
    tracking.When = when;
    session.Save(tracking);
}&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;More, please! &lt;/h4&gt;
&lt;p&gt;You also will find lots of sample usage code in the tests project (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Tests.NHibernate.Spatial&lt;/span&gt;&lt;/span&gt;). Check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://nhcontrib.svn.sourceforge.net/viewvc/nhcontrib/trunk/src/NHibernate.Spatial/src/Tests.NHibernate.Spatial/CriteriaFixture.cs?view=markup"&gt;CriteriaFixture.cs&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nhcontrib.svn.sourceforge.net/viewvc/nhcontrib/trunk/src/NHibernate.Spatial/src/Tests.NHibernate.Spatial/ProjectionsFixture.cs?view=markup"&gt;ProjectionsFixture.cs&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nhcontrib.svn.sourceforge.net/viewvc/nhcontrib/trunk/src/NHibernate.Spatial/src/Tests.NHibernate.Spatial/OgcSfSql11Compliance/ConformanceItemsFixture.cs?view=markup"&gt;OgcSfSql11Compliance/ConformanceItemsFixture.cs&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nhcontrib.svn.sourceforge.net/viewvc/nhcontrib/trunk/src/NHibernate.Spatial/src/Tests.NHibernate.Spatial/RandomGeometries/SpatialQueriesFixture.cs?view=markup"&gt;RandomGeometries/SpatialQueriesFixture.cs&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Sample usage</title><link>http://nhforge.org/wikis/spatial/sample-usage/revision/3.aspx</link><pubDate>Wed, 01 Oct 2008 01:22:23 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:163</guid><dc:creator>Ricardo Stuven</dc:creator><comments>http://nhforge.org/wikis/spatial/sample-usage/comments.aspx</comments><description>Revision 3 posted to Spatial by Ricardo Stuven on 30/09/2008 10:22:23 p.m.&lt;br /&gt;
&lt;h2&gt;Sample usage&lt;/h2&gt;
&lt;h4 class="wikidoc"&gt;Find a country by coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = session.CreateCriteria(typeof(Country))
    .Add(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
    .UniqueResult() as Country;&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = Country.FindOne(
    SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Find all the towns in a bounding box, except the one located at some coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;IList towns = session.CreateCriteria(typeof(Town))
    .Add(SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)))
    .Add(Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))))
    .List();&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Town[] towns = Town.FindAll(
    SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)),
    Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The previous example just shows how to combine a spatial criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Contains&lt;/span&gt;&lt;/span&gt;) with a normal criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Not&lt;/span&gt;&lt;/span&gt;), but in this case we could use simply &lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Disjoint&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h4&gt;Get states boundaries grouping counties by state: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;ProjectionQuery&amp;lt;County&amp;gt; query = new ProjectionQuery&amp;lt;County&amp;gt;(
    Projections.ProjectionList()
        .Add(Projections.GroupProperty(&amp;quot;State&amp;quot;))
        .Add(SpatialProjections.Union(&amp;quot;Boundaries&amp;quot;))
    );
IList&amp;lt;object[]&amp;gt; stateBoundaries= query.Execute();&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For people with a GIS backgroud, the &amp;quot;projection&amp;quot; term could be confusing. In this context, it has nothing to do with cartographic projections. It&amp;#39;s rather a term borrowed from &lt;a href="http://en.wikipedia.org/wiki/Projection_(relational_algebra)" class="externalLink"&gt;&lt;span style="color:#3e62a6;"&gt;relational algebra&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Create a new vehicle GPS position: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;public void TrackVehicule(Vehicle vehicule, double longitude, double latitude, DateTime when)
{
    Tracking tracking = new Tracking();
    tracking.Vehicle = vehicle;
    tracking.Position = new Point(longitude, latitude);
    tracking.When = when;
    session.Save(tracking);
}&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;More, please! &lt;/h4&gt;
&lt;p&gt;You also will find lots of sample usage code in the tests project (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Tests.NHibernate.Spatial&lt;/span&gt;&lt;/span&gt;). Check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CriteriaFixture.cs&lt;/li&gt;
&lt;li&gt;ProjectionsFixture.cs&lt;/li&gt;
&lt;li&gt;OgcSfSql11Compliance/ConformanceItemsFixture.cs&lt;/li&gt;
&lt;li&gt;RandomGeometries/SpatialQueriesFixture.cs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Sample usage</title><link>http://nhforge.org/wikis/spatial/sample-usage/revision/2.aspx</link><pubDate>Wed, 01 Oct 2008 01:17:22 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:161</guid><dc:creator>Ricardo Stuven</dc:creator><comments>http://nhforge.org/wikis/spatial/sample-usage/comments.aspx</comments><description>Revision 2 posted to Spatial by Ricardo Stuven on 30/09/2008 10:17:22 p.m.&lt;br /&gt;
&lt;h2&gt;Sample usage&lt;/h2&gt;
&lt;h4 class="wikidoc"&gt;Find a country by coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = session.CreateCriteria(typeof(Country))
    .Add(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
    .UniqueResult() as Country;&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = Country.FindOne(
    SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Find all the towns in a bounding box, except the one located at some coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;IList towns = session.CreateCriteria(typeof(Town))
    .Add(SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)))
    .Add(Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))))
    .List();&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Town[] towns = Town.FindAll(
    SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)),
    Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;br /&gt;The previous example just shows how to combine a spatial criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Contains&lt;/span&gt;&lt;/span&gt;) with a normal criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Not&lt;/span&gt;&lt;/span&gt;), but in this case we could use simply &lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Disjoint&lt;/span&gt;&lt;/span&gt;.&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h4&gt;Get states boundaries grouping counties by state: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;ProjectionQuery&amp;lt;County&amp;gt; query = new ProjectionQuery&amp;lt;County&amp;gt;(
    Projections.ProjectionList()
        .Add(Projections.GroupProperty(&amp;quot;State&amp;quot;))
        .Add(SpatialProjections.Union(&amp;quot;Boundaries&amp;quot;))
    );
IList&amp;lt;object[]&amp;gt; stateBoundaries= query.Execute();&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For people with a GIS backgroud, the &amp;quot;projection&amp;quot; term could be confusing. In this context, it has nothing to do with cartographic projections. It&amp;#39;s rather a term borrowed from &lt;a class="externalLink" href="http://en.wikipedia.org/wiki/Projection_(relational_algebra)"&gt;&lt;span style="color:#3e62a6;"&gt;relational algebra&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Create a new vehicle GPS position: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;public void TrackVehicule(Vehicle vehicule, double longitude, double latitude, DateTime when)
{
    Tracking tracking = new Tracking();
    tracking.Vehicle = vehicle;
    tracking.Position = new Point(longitude, latitude);
    tracking.When = when;
    session.Save(tracking);
}&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;More, please! &lt;/h4&gt;
&lt;p&gt;You also will find lots of sample usage code in the tests project (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Tests.NHibernate.Spatial&lt;/span&gt;&lt;/span&gt;). Check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CriteriaFixture.cs&lt;/li&gt;
&lt;li&gt;ProjectionsFixture.cs&lt;/li&gt;
&lt;li&gt;OgcSfSql11Compliance/ConformanceItemsFixture.cs&lt;/li&gt;
&lt;li&gt;RandomGeometries/SpatialQueriesFixture.cs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Sample usage</title><link>http://nhforge.org/wikis/spatial/sample-usage/revision/1.aspx</link><pubDate>Fri, 26 Sep 2008 21:35:40 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:160</guid><dc:creator>Ricardo Stuven</dc:creator><comments>http://nhforge.org/wikis/spatial/sample-usage/comments.aspx</comments><description>Revision 1 posted to Spatial by Ricardo Stuven on 26/09/2008 06:35:40 p.m.&lt;br /&gt;
&lt;h4 class="wikidoc"&gt;Find a country by coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = session.CreateCriteria(typeof(Country))
    .Add(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
    .UniqueResult() as Country;&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Country country = Country.FindOne(
    SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Find all the towns in a bounding box, except the one located at some coordinates: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;IList towns = session.CreateCriteria(typeof(Town))
    .Add(SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)))
    .Add(Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24))))
    .List();&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;
&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;Town[] towns = Town.FindAll(
    SpatialExpression.Filter(&amp;quot;Boundaries&amp;quot;, new Envelope(-70, -68, -32, -34)),
    Expression.Not(SpatialExpression.Contains(&amp;quot;Boundaries&amp;quot;, new Point(-70.40, -33.24)))
);&lt;/pre&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;br /&gt;The previous example just shows how to combine a spatial criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Contains&lt;/span&gt;&lt;/span&gt;) with a normal criterion (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Not&lt;/span&gt;&lt;/span&gt;), but in this case we could use simply &lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Disjoint&lt;/span&gt;&lt;/span&gt;.&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h4&gt;Get states boundaries grouping counties by state: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using ActiveRecord: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;ProjectionQuery&amp;lt;County&amp;gt; query = new ProjectionQuery&amp;lt;County&amp;gt;(
    Projections.ProjectionList()
        .Add(Projections.GroupProperty(&amp;quot;State&amp;quot;))
        .Add(SpatialProjections.Union(&amp;quot;Boundaries&amp;quot;))
    );
IList&amp;lt;object[]&amp;gt; stateBoundaries= query.Execute();&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; For people with a GIS backgroud, the &amp;quot;projection&amp;quot; term could be confusing. In this context, it has nothing to do with cartographic projections. It&amp;#39;s rather a term borrowed from &lt;a href="http://en.wikipedia.org/wiki/Projection_(relational_algebra)" class="externalLink"&gt;&lt;span style="color:#3e62a6;"&gt;relational algebra&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Create a new vehicle GPS position: &lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Using NHibernate: &lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;text-transform:none;color:#000000;text-indent:0px;font-family:&amp;#39;Segoe UI&amp;#39;;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;pre style="margin-top:0px;overflow-y:hidden;font-size:1em;overflow-x:auto;font-family:&amp;#39;Courier New&amp;#39;;height:auto;background-color:#ececec;border:#3e62a6 0.1em dashed;padding:0.5em;"&gt;public void TrackVehicule(Vehicle vehicule, double longitude, double latitude, DateTime when)
{
    Tracking tracking = new Tracking();
    tracking.Vehicle = vehicle;
    tracking.Position = new Point(longitude, latitude);
    tracking.When = when;
    session.Save(tracking);
}&lt;/pre&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h4&gt;More, please! &lt;/h4&gt;
&lt;p&gt;You also will find lots of sample usage code in the tests project (&lt;span class="codeInline"&gt;&lt;span style="font-family:Courier New;"&gt;Tests.NHibernate.Spatial&lt;/span&gt;&lt;/span&gt;). Check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CriteriaFixture.cs&lt;/li&gt;
&lt;li&gt;ProjectionsFixture.cs&lt;/li&gt;
&lt;li&gt;OgcSfSql11Compliance/ConformanceItemsFixture.cs&lt;/li&gt;
&lt;li&gt;RandomGeometries/SpatialQueriesFixture.cs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>
