Skip to main content
33 votes

Returning lat and long of centroid point with GeoPandas

Ran into this problem myself. If you want the x and y as separate GeoDataFrame columns, then this works nicely: gdf["x"] = gdf.centroid.map(lambda p: p.x) gdf["y"] = gdf.centroid.map(lambda p: p.y) ...
Martin Valgur's user avatar
21 votes
Accepted

Difference between QgsPoint, QgsPointXY and QgsGeometry.fromPointXY() in PyQGIS

QgsPoint is a point class which supports Z (3D) and M values. (What are Z and M?) x, y, z, m = 10, 10, 20, 5 QgsPoint(x, y) # 2D # <QgsPoint: Point (10 10)> QgsPoint(x, y, z) # 3D # <...
Kadir Şahbaz's user avatar
16 votes
Accepted

Getting coordinates of point on mouse click using PyQGIS

You need QgsMapToolEmitPoint class to do that. Following code works well for that purpose: from qgis.gui import QgsMapToolEmitPoint def display_point( pointTool ): print '({:.4f}, {:.4f})'....
xunilk's user avatar
  • 30k
12 votes

What coordinates Field Calculator used when given $x to get X coordinate in QGIS?

The QGIS field calculator is pretty powerful. So since the file is in EPSG:3879, it will report x and y in EPSG:3879. I don't quite understand why you think it is reporting in EPSG:3067, perhaps you ...
HeikkiVesanto's user avatar
12 votes
Accepted

Updating feature geometry from attribute fields in QGIS

Assuming you have chosen <geometry> field in the Update existing field drop down list, the expression you need would be: geom_from_wkt('POINT('||"x"||' '||"y"||')')
Kazuhito's user avatar
  • 31k
12 votes

Adding x,y coordinates to Attribute table in QGIS

Use a built-in tool "Add X/Y fields to layer" There you can choose a coordinate system in which you want your coordinates and add an optional field prefix.
Trnovstyle's user avatar
11 votes
Accepted

Converting coordinates from cartesian to geodetic in QGIS

The Show coordinates in use option is for visualization purposes. It doesn't affect the expression. You need to transform. Use this for X: x(transform($geometry, @layer_crs, 'EPSG:4326')) and for Y: ...
Kadir Şahbaz's user avatar
10 votes

Adding x,y coordinates to Attribute table in QGIS

Under assumption that you have some kind of a vector layer (such as GeoJSON or something similar) I provide an explanation on the example of a GeoJSON file that contains point features. You didn't ...
Saša Vranić's user avatar
10 votes

Expression to Transform XY coordinates to LatLong in QGIS

If the layer is already georeferenced in QGIS then you can do something like this with the Field Calculator: Expression for longitude: x(transform($geometry, @YOUR_CRS_ID, 'EPSG:4326')) And for ...
Leon Powałka's user avatar
9 votes

What coordinates Field Calculator used when given $x to get X coordinate in QGIS?

Expanding on the answer of @heikkivesanto, the expression can be made more generic as follows: x( transform( $geometry, layer_property(@layer_id, 'crs'), 'EPSG:4326')) This removes the need to copy ...
Andy Harfoot's user avatar
  • 3,377
9 votes
Accepted

Extracting starting and ending points from geometry column in separate columns using GeoPandas

This can make it: import geopandas as gpd from shapely.geometry import Point, LineString line1 = LineString([Point(0,0), Point(-1,-1), Point(2,-3), Point(4,5)]) line2 = LineString([Point(-2,8), Point(...
swiss_knight's user avatar
  • 10.5k
9 votes

Extracting starting and ending points from geometry column in separate columns using GeoPandas

It is easier to use apply and lambda functions: import geopandas as gpd gdf = gpd.read_file(pth_line_shapefile) # Extract start and end coordinates of each linestring first_coord = gdf["geometry&...
Fardin Esmaeili's user avatar
9 votes
Accepted

Extracting x,y coordinates from QgsGeometry: Point(x, y) using PyQGIS

I could get the same exception AttributeError: Traceback (most recent call last): File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "&...
Taras's user avatar
  • 33.3k
8 votes

Convert Lon Lat to XY in Openlayers 3

I was looking for this function too, and I have found it in some of the examples on their site. You can use ol.proj.fromLonLat([19.062072, 47.473478]). http://openlayers.org/en/v3.13.1/apidoc/ol....
Isti115's user avatar
  • 193
8 votes
Accepted

Data Defined Override XY offset input

The correct syntax involves the use of single quotes around the X and Y 'offset_x,offset_y'
Victor's user avatar
  • 1,852
8 votes
Accepted

Create line from csv coordinates

To get this into a useful format as a CSV is going to take some doing. The first step is to open the data in a text editor (like Notepad) and replace the semicolons with commas (edit>replace, or ...
Josh Beauchamp's user avatar
8 votes
Accepted

Extracting X and Y coordinates from .gpx file using QGIS?

You can do Layer... Save As... and choose the CSV output format. Choose Geometry type as POINT and Geometry as AS_XY: Then you'll get a CSV like: X,Y,route_fid,route_point_id,ele,time,magvar,...
Spacedman's user avatar
  • 65.1k
8 votes
Accepted

Automatically generating coordinates of new points features and adding them to feature table in QGIS

The field calculator is used for a one-time calculation. Whenever you add features, the new records will not be populated with the new coordinates. The proper way to do that is in the layers' ...
GforGIS's user avatar
  • 3,126
8 votes
Accepted

Generating x, y, coordinates within polygon/polyline with certain interval in QGIS

Grid is the correct term. If you have a line layer you need to convert it to polygon. Create a point grid using the polygons extent with 500 m x and y spacing Extract the points inside the polygon ...
Bera's user avatar
  • 74.8k
7 votes

Converting while reading a shapefile

Using ogr2ogr The simplest way to do this is probably to just use ogr2ogr, no need for code. Something like this:- ogr2ogr -f GeoJSON -s_srs XXXX -t_srs 4326 output.geojson input.shp Replace XXXX ...
Steven Kay's user avatar
  • 20.5k
7 votes

Adding x,y coordinates to Attribute table in QGIS

A possible solution using PyQGIS. Let's assume there is a point layer called 'points' with its attribute table, see image below. Proceed with Plugins > Python Console > Show Editor (Ctrl+Alt+P) ...
Taras's user avatar
  • 33.3k
6 votes

Returning lat and long of centroid point with GeoPandas

This has been made easier as of GeoPandas 0.3.0. You can now access x and y of shapely Points inside a geopandas GeoSeries using your_GeoDataFrame.geometry.x and your_GeoDataFrame.geometry.y (Note : ...
François M.'s user avatar
6 votes

Go To XY not working in ArcMap

Things that I would try in this order are: click on another button in the same toolbar, and then click this button again. I have seen this behaviour from the Measure tool on that toolbar. close ...
PolyGeo's user avatar
  • 65.2k
6 votes

Identify X Y coordinates of polygons and add them to the attribute table in QGIS?

The QGIS field calculator can do it with these built-in functions: x($geometry) y($geometry) Make sure to create a new field of type real, with an appropriate accuracy. You can even use a virtual ...
AndreJ's user avatar
  • 76.7k
6 votes
Accepted

Scaling more than 1000 polygons in QGIS

In QGIS you can create a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer.... with a SpatiaLite expression to perform the transformation that you need: SELECT ...
Gabriel De Luca's user avatar
6 votes
Accepted

Exporting x,y coordinates as latitude,longitude in QGIS

Before exporting there are several more steps have to be applied. Step 1. Create two additional fields, i.e. "lat" and "long" via the Field Calculator Step 2. Apply the following ...
Taras's user avatar
  • 33.3k
6 votes
Accepted

Converting x,y coordinates (EPSG:102002) to latitude,longitude (EPSG:4326)

You can use QGIS: Add delimited text layer Reproject Layer Add geometry attributes
Bera's user avatar
  • 74.8k
6 votes
Accepted

Making polygon from list of xy coordinates using Shapely

The shapely Polygon class constructor can receive a sequence of coordinate tuples, which you can create using the zip function. p = Polygon(list(zip(xv, yv))) or even simpler, you may as well create ...
CodeBard's user avatar
  • 3,581
6 votes
Accepted

Rounding decimal numbers in PostGIS

Via Round ST_Distance you need to cast the values to a numeric: select name, round(ST_X(geom)::numeric, 2) as x_coordinate, round(ST_Y(geom)::numeric, 2) as y_coordinate from cities You could ...
bugmenot123's user avatar
  • 10.9k
6 votes

Importing points from CSV file with NaN as vertical separator in QGIS

You can: Add the coordinates as a delimited text layer (Ctrl+Shift+T) DBSSCAN clustering with Minimum cluster size = 2 and Maximum distance between points = 50. This will add the attribute CLUSTER_ID ...
Bera's user avatar
  • 74.8k

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