Go to content Go to navigation Go to search

Featured Articles:

    Applying And Extending Oracle Spatial - Book Released
    Analyzing Spatial Query Performance Improvements in Oracle Spatial and Graph 12c Through Cross-Vendor Comparison

Newest Article:

SQL Server Spatial: Converting COGO instructions to LineString.

Monday June 25 2018 at 15:39

Previously I wrote about a function that converted the segments of a linestring into COGO instructions (bearing and distances).

Today I present a function that does the reverse: converts a collection of COGO instructions into a linestring.

The instructions are provided to the function in an XML document with the following structure:

  1. <Cogo>
  2.   <Segments>
  3.     <Segment>
  4.       <sDegMinSec></sDegMinSec>
  5.       <Bearing></Bearing>
  6.       <Distance></Distance>
  7.       <DeltaZ></DeltaZ>
  8.     <Segment>
  9.     <Segment>
  10.       ....
  11.     <Segment>
  12.   </Segments>
  13. </Cogo>
  14. -- <sDegMinSec> does not have to exist if <Bearing> (decimal degrees) exists.
  15. -- <DeltaZ> is optional. If supplied start point must exist and have a Z ordinate.

The function looks like this (see SQL Server documentation on this site).

  1. CREATE FUNCTION [$(cogoowner)].[STCogo2Line]
  2. (
  3.   @p_cogo        xml,
  4.   @p_start_point geometry,
  5.   @p_round_xy    INT = 3,
  6.   @p_round_z     INT = 2
  7. )
  8. RETURNS geometry
  9. .....

Here is an example showing how to call the function:

  1. DECLARE @v_cogo xml;
  2. SET @v_cogo =
  3. '<Cogo><Segments>
  4. <Segment><sDegMinSec> 345°21''48.75"</sDegMinSec><Distance>7.26992</Distance><DeltaZ>1</DeltaZ></Segment>
  5. <Segment><sDegMinSec>  83° 2''4.652"</sDegMinSec><Distance>151.712</Distance><DeltaZ>2</DeltaZ></Segment>
  6. <Segment><sDegMinSec> 186°34''30.73"</sDegMinSec><Distance>10.3924</Distance><DeltaZ>3</DeltaZ></Segment>
  7. <Segment><sDegMinSec>  86° 2''48.18"</sDegMinSec><Distance>13.3879</Distance><DeltaZ>4</DeltaZ></Segment>
  8. <Segment><sDegMinSec> 187° 5''20.73"</sDegMinSec><Distance>9.09956</Distance><DeltaZ>5</DeltaZ></Segment>
  9. <Segment><sDegMinSec>  89°20''48.85"</sDegMinSec><Distance>61.061</Distance><DeltaZ>6</DeltaZ></Segment>
  10. <Segment><sDegMinSec> 359°49''6.930"</sDegMinSec><Distance>11.6861</Distance><DeltaZ>7</DeltaZ></Segment>
  11. <Segment><sDegMinSec>  96°21''55.47"</sDegMinSec><Distance>11.0401</Distance><DeltaZ>8</DeltaZ></Segment>
  12. <Segment><sDegMinSec> 355° 3''18.45"</sDegMinSec><Distance>28.1448</Distance><DeltaZ>9</DeltaZ></Segment>
  13. <Segment><sDegMinSec>  82°59''21.42"</sDegMinSec><Distance>5.59584</Distance><DeltaZ>10</DeltaZ></Segment>
  14. </Segments></Cogo>';
  15. SELECT cogoLine, cogoLine.AsTextZM() AS cogoLineWKT
  16.   FROM (SELECT [$(cogoowner)].[STCogo2Line] (@v_cogo, geometry::STPointFromText('POINT(10 10 -10)',28355), 3, 2) AS cogoLine) AS f;
  17. GO

The result looks like this:

P. Which should be the same as STLine2Cogo.

The WKT of the object is:

  1. LINESTRING (10 10 -10, 8.163 17.034 -9, 158.755 35.432 -7, 157.565 25.108 -4, 170.921 26.031 0, 169.798 17.001 5, 230.855 17.697 11, 230.818 29.383 18, 241.79 28.159 26, 239.364 56.199 35, 244.918 56.882 45)

I hope this function is of interest to someone.

My Services

I offer the following services to customers:

  1. Integration of GeoSpatial within IT
    Advice and guidance on how to fully integrate geospatial data and processing needs within existing, pure, IT environments (using existing GIS software or without purchasing proprietary GIS software);
  2. Independent Solutions Advice and Sanity Checking
    Solutions not Software ;
    How to efficiently and effectively solve a business requirement via existing technology;
    Does what you have been offered in a tender really stack up? Or do you want independent quality assurance of a tender document before submitting it to a customer?
    When it is best to use Open Source as against Commercial off the shelf (COTS) and vice versa?
    Is buzzword-compliant (SOA, BPEL, J2EE, .NET, WebServices…) technology really needed to solve a business problem? If so, what is the best way to achieve this?
    ;
  3. Analyzing ROI of your current GIS software technology
    Matching business problems to existing software investment. Are you getting value from your software investment? How to improve that ROI;
  4. Systems Review
    Does the solution you have been provided actually match your requirements?;
  5. Database Benchmarking:
    How well are you using your Oracle Spatial/SQL Server Spatial/PostGIS database?
    How good is your databases documentation/metadata?
    Is the integrity and quality of the data stored in your databases as good as you think?
    Is your use of Oracle (Spatial), SQL Server Spatial consistent with industry best-practice?
    Get advice on some simple “rules” to follow to improve your database!
  6. Database Consulting through design, test, build and configuration services
    Ensuring your databases reflect your needs via:
    1. Data Quality Rules Documentation, Conformance Testing, Correction and Certification;
    2. Data Conversion, Migration, Loading;
    3. Database Design;
    4. Coding of appropriate in-Database processing:
      Via design and coding services in:
      1. PL/SQL – Oracle,
      2. PL/pgSQL – PostgreSQL,
      3. T-SQLSQL Server,
      4. Java,
      5. C#.
    5. Database Performance Tuning;
    6. Spatially enabling Data Warehouses and Processes;
    7. ArcSDE Configuration and Tuning.
  7. SpatialDB Training Courses and Staff Mentoring
    Spatial SQL Training on your datasets;
    After Training support
    ;
  8. Free Software
  9. Commercial Support
    GeoRaptor
    Free PL/SQL packages
    (bug fixes, extensions and new functionality).

I have over 25 years experience with database technologies from mainframes through to personal computers. I have 25 years Oracle use and am recognised by the Oracle Spatial development team as one of the early adopters of Oracle’s Sdo_Geometry data type. In 2011 that experience was recognised when Oracle awarded me the “2011 Oracle Spatial Excellence Award for Education and Research”.

I was on the original beta program for SQL Server 2008 Spatial (aka “Katmai”). While most of my solutions work centres on Oracle, I now have quite a few years experience designing, programming, tuning and working with SQL Server. I make available over 200 TSQL functions to SQL Server Spatial users across multiple versions.

I also have the necessary PostgreSQL/PostGIS and MySQL experience to help you implement the best spatial database solution possible.

I have (next to the original designer and programmer) the longest experience of using ArcSDE in the industry and can help you get the best out of this piece of ESRI software and show you how to make it work with other spatial software (esp open source). Also, with the new ESRI Spatial Type for Oracle, PostgreSQL and SQL Server, I am in a unique position to help you plan your migrations from SDEBINARY to either the ESRI Spatial Type, SQL Server spatial or Oracle’s Sdo_Geometry.

My experience is not limited just to databases. I have managed “GIS” infrastructure management teams, designed and built systems integrating spatial processing within business systems in the areas of mapping, editing, analysis, GPS field data capture etc.

Finally, as a geospatial professional with IT and Oracle (Certified Professional SQL 10gR2; Certified Associate DBA 10gR2) qualifications and experience, I can help guide the uptake of geospatial technologies into business’s IT infrastructures.

Let me help you cost-effectively spatially-enable your enterprise.