none
STNumPoints

    Question

  • I am trying to return the number of points in Each Line Segment where the Table is a collection (rows) of unique Line Segments, using the method STNumPoints(). 

    I have WKT and geometry data type for each instance (line segment), and would like to populate an entire column with the number of points in each  segment. 

    I don't really have a clue how to use this function to generate the desired column, and have been unsuccessful with anything I've tried. 

    Any clues????

    thx

    Spatio

    Tuesday, November 19, 2013 9:57 PM

Answers

  • Here's a basic usage sample, both in a SELECT statement or as a computed column.  Does this help?

    USE tempdb;
    
    GO
    
    --setup test data
    CREATE TABLE specialspatial (
    	 id int
    	,line geometry
    	);
    
    INSERT specialspatial VALUES 
     (1, geometry::STLineFromText('LINESTRING(10 10, 20 20, 30 30)', 0))
    ,(2, geometry::STLineFromText('LINESTRING(-10 10, -20 20)', 0))
    ,(3, geometry::STLineFromText('LINESTRING(10 -10, 20 -20, 30 -30, 40 -40)', 0));
    
    --simple usage of STNumPoints
    SELECT id
    	,line.STNumPoints()
    FROM specialspatial;
    
    --OR as a calculated column
    ALTER TABLE specialspatial ADD numpoints AS line.STNumPoints();
    
    SELECT * FROM specialspatial;


    Jason

    • Marked as answer by spatio Thursday, December 12, 2013 5:35 AM
    Tuesday, November 19, 2013 10:36 PM
  • Sure DID, Dude!

    THX

    S

    • Marked as answer by spatio Tuesday, November 19, 2013 11:00 PM
    Tuesday, November 19, 2013 10:48 PM

All replies

  • Here's a basic usage sample, both in a SELECT statement or as a computed column.  Does this help?

    USE tempdb;
    
    GO
    
    --setup test data
    CREATE TABLE specialspatial (
    	 id int
    	,line geometry
    	);
    
    INSERT specialspatial VALUES 
     (1, geometry::STLineFromText('LINESTRING(10 10, 20 20, 30 30)', 0))
    ,(2, geometry::STLineFromText('LINESTRING(-10 10, -20 20)', 0))
    ,(3, geometry::STLineFromText('LINESTRING(10 -10, 20 -20, 30 -30, 40 -40)', 0));
    
    --simple usage of STNumPoints
    SELECT id
    	,line.STNumPoints()
    FROM specialspatial;
    
    --OR as a calculated column
    ALTER TABLE specialspatial ADD numpoints AS line.STNumPoints();
    
    SELECT * FROM specialspatial;


    Jason

    • Marked as answer by spatio Thursday, December 12, 2013 5:35 AM
    Tuesday, November 19, 2013 10:36 PM
  • Sure DID, Dude!

    THX

    S

    • Marked as answer by spatio Tuesday, November 19, 2013 11:00 PM
    Tuesday, November 19, 2013 10:48 PM
  • Glad I was able to help. If you could mark my reply (instead of your own) as the answer that would be great. Thanks!


    Jason

    Tuesday, November 19, 2013 11:18 PM
  • Thanks Jason, 

    I think I fixed that, 

    thanks Again, 

    Frank

    Thursday, December 12, 2013 5:36 AM