EnhancedPrecisionOp.cs :  » GIS » DeepEarth » GisSharpBlog » NetTopologySuite » Precision » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » DeepEarth 
DeepEarth » GisSharpBlog » NetTopologySuite » Precision » EnhancedPrecisionOp.cs
using System;
using GeoAPI.Geometries;

namespace GisSharpBlog.NetTopologySuite.Precision{
    /// <summary>
    /// Provides versions of Geometry spatial functions which use
    /// enhanced precision techniques to reduce the likelihood of robustness problems.
    /// </summary>
    public class EnhancedPrecisionOp
    {
        /// <summary>
        /// Only static methods!
        /// </summary>
        private EnhancedPrecisionOp() { }

        /// <summary>
        /// Computes the set-theoretic intersection of two <c>Geometry</c>s, using enhanced precision.
        /// </summary>
        /// <param name="geom0">The first Geometry.</param>
        /// <param name="geom1">The second Geometry.</param>
        /// <returns>The Geometry representing the set-theoretic intersection of the input Geometries.</returns>
        public static IGeometry Intersection(IGeometry geom0, IGeometry geom1)
        {
            SystemException originalEx = null;
            try
            {
                IGeometry result = geom0.Intersection(geom1);
                return result;
            }
      catch (SystemException ex)
            {
                originalEx = ex;
            }
            /*
             * If we are here, the original op encountered a precision problem
             * (or some other problem).  Retry the operation with
             * enhanced precision to see if it succeeds
             */
            try
            {
                CommonBitsOp cbo = new CommonBitsOp(true);
                IGeometry resultEP = cbo.Intersection(geom0, geom1);
                // check that result is a valid point after the reshift to orginal precision
                if (!resultEP.IsValid)
                    throw originalEx;
                return resultEP;
            }
      catch (SystemException)
            {
                throw originalEx;
            }
        }

        /// <summary>
        /// Computes the set-theoretic union of two <c>Geometry</c>s, using enhanced precision.
        /// </summary>
        /// <param name="geom0">The first Geometry.</param>
        /// <param name="geom1">The second Geometry.</param>
        /// <returns>The Geometry representing the set-theoretic union of the input Geometries.</returns>
        public static IGeometry Union(IGeometry geom0, IGeometry geom1)
        {
      SystemException originalEx = null;
            try
            {
                IGeometry result = geom0.Union(geom1);
                return result;
            }
      catch (SystemException ex)
            {
                originalEx = ex;
            }
            /*
             * If we are here, the original op encountered a precision problem
             * (or some other problem).  Retry the operation with
             * enhanced precision to see if it succeeds
             */
            try
            {
                CommonBitsOp cbo = new CommonBitsOp(true);
                IGeometry resultEP = cbo.Union(geom0, geom1);
                // check that result is a valid point after the reshift to orginal precision
                if (!resultEP.IsValid)
                    throw originalEx;
                return resultEP;
            }
      catch (SystemException)
            {
                throw originalEx;
            }
        }

        /// <summary>
        /// Computes the set-theoretic difference of two <c>Geometry</c>s, using enhanced precision.
        /// </summary>
        /// <param name="geom0">The first Geometry.</param>
        /// <param name="geom1">The second Geometry.</param>
        /// <returns>The Geometry representing the set-theoretic difference of the input Geometries.</returns>
        public static IGeometry Difference(IGeometry geom0, IGeometry geom1)
        {
      SystemException originalEx = null;
            try
            {
                IGeometry result = geom0.Difference(geom1);
                return result;
            }
      catch (SystemException ex)
            {
                originalEx = ex;
            }
            /*
             * If we are here, the original op encountered a precision problem
             * (or some other problem).  Retry the operation with
             * enhanced precision to see if it succeeds
             */
            try
            {
                CommonBitsOp cbo = new CommonBitsOp(true);
                IGeometry resultEP = cbo.Difference(geom0, geom1);
                // check that result is a valid point after the reshift to orginal precision
                if (!resultEP.IsValid)
                    throw originalEx;
                return resultEP;
            }
      catch (SystemException)
            {
                throw originalEx;
            }
        }

        /// <summary>
        /// Computes the set-theoretic symmetric difference of two <c>Geometry</c>s, using enhanced precision.
        /// </summary>
        /// <param name="geom0">The first Geometry.</param>
        /// <param name="geom1">The second Geometry.</param>
        /// <returns>The Geometry representing the set-theoretic symmetric difference of the input Geometries.</returns>
        public static IGeometry SymDifference(IGeometry geom0, IGeometry geom1)
        {
      SystemException originalEx = null;
            try
            {
                IGeometry result = geom0.SymmetricDifference(geom1);
                return result;
            }
      catch (SystemException ex)
            {
                originalEx = ex;
            }
            /*
             * If we are here, the original op encountered a precision problem
             * (or some other problem).  Retry the operation with
             * enhanced precision to see if it succeeds
             */
            try
            {
                CommonBitsOp cbo = new CommonBitsOp(true);
                IGeometry resultEP = cbo.SymDifference(geom0, geom1);
                // check that result is a valid point after the reshift to orginal precision
                if (!resultEP.IsValid)
                    throw originalEx;
                return resultEP;
            }
      catch (SystemException)
            {
                throw originalEx;
            }
        }

        /// <summary>
        /// Computes the buffer of a <c>Geometry</c>, using enhanced precision.
        /// This method should no longer be necessary, since the buffer algorithm
        /// now is highly robust.
        /// </summary>
        /// <param name="geom">The first Geometry.</param>
        /// <param name="distance">The buffer distance.</param>
        /// <returns>The Geometry representing the buffer of the input Geometry.</returns>
        [Obsolete("This method should no longer be necessary, since the buffer algorithm now is highly robust.")]
        public static IGeometry Buffer(IGeometry geom, double distance)
        {
      SystemException originalEx = null;
            try
            {
                IGeometry result = geom.Buffer(distance);
                return result;
            }
      catch (SystemException ex)
            {
                originalEx = ex;
            }
            /*
             * If we are here, the original op encountered a precision problem
             * (or some other problem).  Retry the operation with
             * enhanced precision to see if it succeeds
             */
            try
            {
                CommonBitsOp cbo = new CommonBitsOp(true);
                IGeometry resultEP = cbo.Buffer(geom, distance);
                // check that result is a valid point after the reshift to orginal precision
                if (!resultEP.IsValid)
                    throw originalEx;
                return resultEP;
            }
      catch (SystemException)
            {
                throw originalEx;
            }
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.