30 votes
Accepted

Calculating area in km² for Polygon in WKT using Python

It wasn't readily apparent to me how to use @sgillies answer, so here is a more verbose version: import pyproj import shapely import shapely.ops as ops from shapely.geometry.polygon import Polygon ...
jczaplew's user avatar
  • 1,208
27 votes
Accepted

Converting geoalchemy2.elements.WKBElement to WKT

GeoAlchemy supports the PostGIS functions ST_AsText and ST_AsGeoJSON. You can use these in your query to return a WKT/GeoJSON string from the database instead of the WKBElement itself. from ...
Ali's user avatar
  • 4,025
19 votes

Loading WKT polygons into QGIS

Go to Layer -> Add Layer -> Add Delimited Text Layer. You should be able to find the csv file you have, give it a layer name, and choose file format as CSV. In the Geometry Definition, you will have ...
weiji14's user avatar
  • 1,741
17 votes

Visualising WKT geometry string in QGIS

No Plugin required In QGIS deploy a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer.... In the Query window simply paste the following expression: SELECT ...
Taras's user avatar
  • 31.4k
15 votes
Accepted

Getting correct WKT result to 4 decimal places using PostGIS

The simplest way to round geometry coordinates is to use ST_SnapToGrid: SELECT ST_AsText(ST_SnapToGrid('POINT(-0.685239554498251 51.4940418030595)', 0.0001)); st_astext ----------------------- ...
Mike T's user avatar
  • 41.8k
15 votes
Accepted

Is there a way in QGIS 3 to get a selected feature WKT?

I am not sure if this was actually part of QGIS 2.x since I always used the getWKT plugin. But the WKT is accessible from the Identify window context menu: Result: wkt_geom id OBJECTID ...
Jay Cummins's user avatar
  • 14.6k
13 votes

Visualising WKT geometry string in QGIS

In QGIS >=3.18.3 we can copy one or multiple WKT strings into clipboard and paste them using Edit > Paste Feature As > Temporary Scratch Layer... into map canvas. CRS needs to be adjusted ...
christoph's user avatar
  • 5,348
13 votes
Accepted

Quick way to get WKT from a GeoDataFrame's geometries in GeoPandas?

UPDATE: As of GeoPandas 0.9, there is a to_wkt method. mydf['wkt'] = mydf.geometry.to_wkt() Yes, there is to_wkt method in semi-private array module. I think it should be public in future, will have ...
martinfleis's user avatar
  • 2,357
12 votes
Accepted

Export geography field from SQL for use in GIS

You should be able to use STAsText: https://msdn.microsoft.com/en-us/library/bb933977.aspx So you could create a new table: CREATE TABLE wkt_export as SELECT *, RoadGeometry.STASText() as WKT FROM ...
HeikkiVesanto's user avatar
11 votes

How to return WKT of entire polygon with shapely?

You can just use .wkt as wkt_polygon = ShapelyPolygon(..).wkt
Atihska's user avatar
  • 381
10 votes

Calculating area in km² for Polygon in WKT using Python

The other answers seem to be correct, except that at some point, the lat1 and lat2 parameters in the pyproj code were renamed with underscores: lat_1 and lat_2 (see https://stackoverflow.com/a/...
MartinThurn's user avatar
10 votes
Accepted

How do I convert WKT geometry from 3D to 2D

Using of FlattenTo2D() method is correct way, but the method does not returns new object (like you expected) - it changes current object. So you should use the method like this: g = ogr....
Tonny's user avatar
  • 555
10 votes
Accepted

How to generate WKT geometries from true type font glyphs (python)

1) You can use TTFQuery as in Retrieving bounding box and bezier curve data for all glyphs in a .ttf font file in python from ttfquery import describe from ttfquery import glyphquery import ttfquery....
gene's user avatar
  • 54.4k
10 votes
Accepted

Changing coordinate of point using its WKT and PyQGIS

I guess you want to move a box' centroid position to another point if it has a common attribute with the point. I assume ID_PARENT and CODE are unique values. Use this script: box_layer = QgsProject....
Kadir Şahbaz's user avatar
10 votes

Why do single-part WKT polygon vertices require double parentheses?

It is because polygons can have multiple rings in them, the exterior and a list of interior rings or holes. To save parsers having to guess if there are holes by the number of brackets there are ...
Ian Turton's user avatar
  • 80.5k
10 votes

Why do single-part WKT polygon vertices require double parentheses?

@user30184 already gave the short answer in the comments here. For a longer answer, one needs to look to the Simple Feature Access - Part 1: Common Architecture | OGC standard. The Well-known Text (...
bixb0012's user avatar
  • 1,824
9 votes

How to get WKT from a QgsGeometry object?

In QGIS 3 there was a backwards incompatible change about this: exportToWkt() was renamed to asWkt() So now it is: your_string = geom.asWkt()
bugmenot123's user avatar
  • 10.8k
9 votes
Accepted

Converting WKT to SHP?

If it's a one-off operation, you can install the QuickWKT plugin for QGIS. Press the Black/Red WKT Button: and enter your WKT: And press OK. That will add the layer. Then right-click to save the ...
Jay Cummins's user avatar
  • 14.6k
9 votes

Is there a way in QGIS 3 to get a selected feature WKT?

Not sure if this fills your needs but you can (and always could) get the WKT from the field calculator by adding a virtual layer with: geomToWKT( $geometry )
Marco's user avatar
  • 3,210
8 votes

Calculating area in km² for Polygon in WKT using Python

Calculate a geodesic area, which is very accurate and only requires an ellipsoid (not a projection). This can be done with pyproj 2.3.0 or later. from pyproj import Geod from shapely import wkt # ...
Mike T's user avatar
  • 41.8k
8 votes

Loading WKT polygons into QGIS

If you add a header line with "wkt;" you can drag the file directly into QGIS canvas: wkt; POLYGON((...)) Instead of the semicolon you can also use a colon (,) or a tab.
christoph's user avatar
  • 5,348
8 votes
Accepted

QGIS, WKT (Well Known Text) LINES and POLYGON files loaded ok, but POINT not

Your point layer coordinates are flipped. The template for WKT is (x,y), where as Geographic coordinates are (y,x) = (lat,lon). Alas, your Line and Polygon features are corrupted as well. The comma ...
HDunn's user avatar
  • 8,566
8 votes
Accepted

What's this PROJ4 string in WKT?

Technically, I think you have two questions. The first is just what's the WKT for this PROJ.4 string. The second is about how a CRS WKT is structured. An answer to the second question is probably too ...
mkennedy's user avatar
  • 18.8k
8 votes

How to return WKT of entire polygon with shapely?

To get wkt outer ring of a polygon with shapely, you can use next code with your particular paths: import fiona from shapely.geometry import shape, LineString path = '/home/zeito/pyqgis_data/polygon1....
xunilk's user avatar
  • 29.7k
8 votes

PostGis vs Oracle Spatial 11g performance

Oracle Spatial and Postgis both have their own pros and cons. While dealing with the spatial data Postgis always outperform Oracle Spatial. I have been working for last 2 year on Oracle Spatial and i ...
Ahsan Mukhtar's user avatar
8 votes

Is there a way in QGIS 3 to get a selected feature WKT?

You could also use the following in the Python Console (although your method would be quicker): layer = iface.activeLayer() for feat in layer.selectedFeatures(): print(feat.geometry().asWkt())
Joseph's user avatar
  • 75.3k
8 votes
Accepted

is it possible to open a geotiff file in python without using gdal?

It's possible to read the TIFF metadata tags using the Pillow library. This may be easier to set up than GDAL (although it still has numpy as a dependency) I don't seem to be able to open all ...
Steven Kay's user avatar
  • 20.3k
8 votes
Accepted

Convert WKT coordinate reference system to PROJ4

Use the rgdal package and showP4: Your string: > ps [1] "COMPD_CS[\"Projected\", PROJCS[\"UTM_10N\", GEOGCS [ \"WGS84\", DATUM [ \"WGS84\", SPHEROID [\"WGS 84\", 6378137.000, 298.257223563 ], ...
Spacedman's user avatar
  • 62.7k
8 votes

Adding field with geometry in WKT format in QGIS

You need to both (i) create a new string attribute with a high character limit and (ii) use the field calculator to convert the geometry to its WKT representation. Use the field calculator as shown ...
Riccardo's user avatar
  • 2,628
7 votes
Accepted

Visualize WKT polygon on a map

Yes. QGIS: the QuickWKT plugin. The description of the tool is as follows: Quick WKT/WKB viewer, this Qgis Plugin opens a dialog where the user can paste (E)WKT and WKB code and see it on the ...
alphabetasoup's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible