3 Replies Latest reply on Feb 4, 2019 10:21 AM by Marina Derechinskaya

# Convert WKT string Polygons to geometry Points

Hello,

we have data that contais WKT strings with Polygon data. We were able to convert the WKT to Polygon use rawsql_spatial function in Tableau 2018.2. Is there a way to find a polygon's centroid using Tableau from the raw_sql function? That would convert this to Geometry Point?

we're trying to find how many points are within a zip code region. The zip code region is on a separate spatial shapefile.

Thank You

Marina

• ###### 2. Re: Convert WKT string Polygons to geometry Points

It sounds like you have your dataset in a SQL Server database, so you could try:

Calculate the Envelope Center on the polygon (geography data type) - the raqsql would look something like this (I'm not sure how the envelope center will compare to the centroid calculated on the geometry, but it sounded sort of in the ballpark...):

Or, if you have a geometry data type as well, you could use the STCentroid() function:

Or, you could convert your geography to geometry, calculate the centroid using STCentroid, and then cast back to geography.

-Sarah

Tableau Research

3 of 3 people found this helpful
• ###### 3. Re: Convert WKT string Polygons to geometry Points

This helped! Thank You! We're now able to use the Points to Intersect with other ShareFiles in 2018.2 . The example is to create a heat map of points within a zip code boundary region.

We had to do the following:

select *,

(Geography::STPointFromText(Concat('POINT(',((GEOMETRY::STPolyFromText(GeocodeGeometryWKT,4326)).STCentroid()).STX, ' ',  ((GEOMETRY::STPolyFromText(GeocodeGeometryWKT,4326)).STCentroid()).STY , ')'), 4326)) as GeoCenter

from <our table containing WKT>

1)      Calculates center of Geometry

2)      Converts center to X and Y coordinates

3)      Concatenates that into a STRING of a POINT

4)      Converts POINT to Geography

5) Import as custom SQL in Tableau

1 of 1 people found this helpful