A way of converting svg into spatial queries

Zolotoy 226 Reputation points
2021-04-20T18:56:12.63+00:00

Is there a way of converting svg code into SQL spatial queries?

Thanks

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
0 comments No comments
{count} votes

8 answers

Sort by: Most helpful
  1. MelissaMa-msft 24,246 Reputation points Moderator
    2021-04-21T01:37:44.38+00:00

    Hi @Zolotoy ,

    Welcome to Microsoft Q&A!

    You could try to firstly converts SVG (Scalable Vector Graphics) into WKT (Well-Known Text), a markup language for representing vector geometry on maps implemented by spatially-enabled databases like SQL Server and MySQL.

    Please refer a little library called SVG-to-WKT that does the conversion.

    Example:

    SVGtoWKT.convert('<svg><polygon points="1,2 3,4 5,6" /><line x1="7" y1="8" x2="9" y2="10" /></svg>');  
    >>> "GEOMETRYCOLLECTION(POLYGON((1 -2,3 -4,5 -6,1 -2)),LINESTRING(7 -8,9 -10))"  
    

    Secondly you could work with WKT in SQL Server as below:

     create table geometry_polygons(  
         id int identity(1,1) ,  
         polygon geometry,  
         label varchar(50),  
         area decimal(10,4));  
      
     declare @g geometry;   
     set @g=geometry::STGeomFromText('POLYGON((175.0305935740471 -39.924665194652604,175.03033608198166 -39.924387504970255,175.0301563739777 -39.92449035313209,175.03041118383408 -39.92474952981466,175.0305935740471 -39.924665194652604))', 4326);    
     insert into geometry_polygons (polygon) values (@g);  
      
     select * from geometry_polygons  
    

    89610-sql.png

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

  2. Ronen Ariely 15,216 Reputation points
    2021-04-24T08:25:19.987+00:00

    Would it be possible to show the results of a spatial query in a SSRS report?

    Obviously you can. It is very common.

    Think about it... Spatial Data are by definition values which meant to present visualize of "location".

    For Geographic data type you can add a Map to Your Report, and add your Geographic data above the map. There is a Map Wizard and Map Layer Wizard build in which you can use.

    Check this full document on this topic:
    https://learn.microsoft.com/en-us/sql/reporting-services/report-design/maps-report-builder-and-ssrs?view=sql-server-ver15

    1 person found this answer helpful.
    0 comments No comments

  3. mark goldin 706 Reputation points
    2021-04-21T09:46:12.683+00:00

    Will something like this work?

    89845-image.png

    Also, what about css classes? Are they ignored?

    Thanks

    0 comments No comments

  4. mark goldin 706 Reputation points
    2021-04-22T12:46:34.957+00:00

    I am running your SQL code and I get this:
    90337-image.png

    Where do I go from here?


  5. Ronen Ariely 15,216 Reputation points
    2021-04-22T16:25:37.107+00:00

    Here is a full awesome tutorial with example of presenting images in SSMS

    https://www.linkedin.com/pulse/simple-guide-drawing-sql-server-ssms-technical-article-sullivan/?trk=public_profile_article_view

    Notice that the main part of convert the SVG code into WKT is NOT don in transact SQL but by using external tool which is the same as MelissaMa-msft solution (which does not fully cover your question in transact sql forum) - MelissaMa-msft solution uses JS to make this part while the link above simply use an online convert service. To do this part in Transact SQL is possible but can be very long to write and I am not familiar with such code (and did not find such code in Google)

    This image is one of the samples in this tutorial
    90366-image.png

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.