Skip to main content
11 votes
Accepted

Adding elevation, name and description in GeoJSON when converting DataFrame with Python

Using what i learned from the answer of @gene this solution avoids the use of iterrows because iterrows have performance issues. Valid for Python 3.X import pandas as pd import geojson def ...
jrovegno's user avatar
  • 293
10 votes
Accepted

Converting DataFrame to GeoDataFrame with Polygon

geometry column is not in WKT format. Therefore you need a custom method similar to geopandas.point_from_xy. You can use the following script. polygons_from_custom_xy_string method is string-specific. ...
Kadir Şahbaz's user avatar
9 votes
Accepted

Data driven pages for multiple frames

How about setting the second and third frame extent as dependant from the first one (in arcmap), and set your DD pages on the first frame? As your data driven pages flick through the features in the ...
Hélène's user avatar
  • 1,171
9 votes
Accepted

r - create multipolygon from overlapping polygons using sf package

You can do the intersection of polygons and then filter those that overlap. inter <- st_intersection(poly) %>% filter(n.overlaps < 2) plot(inter %>% select(var)
sebdalgarno's user avatar
  • 1,733
9 votes
Accepted

Read N number of rows from shapefile using GeoPandas

Geopandas 0.7 added a new rows parameter to read_file. You can use it to read the first n rows, or a specific slice of rows. import geopandas as gpd # Read the first 100 rows gdf = gpd.read_file(&...
Yoann Quenach de Quivillic's user avatar
9 votes
Accepted

Joining two Pandas DataFrames based on lat, long as fields

Create Pandas DataFrame Create GeoPandas DataFrame using #1 Create Buffer for Points sjoin both GeoDataFrame df1 = pd.DataFrame({ 'name': ['post', 'sutter', 'oak'], 'Lat': [37.788151, ...
Aman Bagrecha's user avatar
8 votes
Accepted

Display extent indicators in the legend?

I don't believe you can do this, but one workaround is to add a dummy polygon layer to your project which has no features in it, but has the same symbology as your extent indicator. Add that layer to ...
Dan C's user avatar
  • 12.3k
8 votes

Read N number of rows from shapefile using GeoPandas

See Only read specific rows of a shapefile with GeoPandas / Fiona: import geopandas as gpd import fiona c = fiona.open(r'C:\someshapefile.shp') df = gpd.GeoDataFrame.from_features(c[0:5])
Bera's user avatar
  • 74.9k
7 votes
Accepted

Move legend if it overlaps features within dataframe using ArcPy

Inputs: Script: import arcpy, traceback, os, sys, time from arcpy import env import numpy as np env.overwriteOutput = True outFolder=arcpy.GetParameterAsText(0) env.workspace = outFolder dpi=2000 ...
FelixIP's user avatar
  • 23.2k
7 votes
Accepted

Why is Label Placement Menu Different with Additional Data Frame in ArcMap?

Turn on the "Labeling" toolbar. Check the box beside 'Use Maplex Label Engine', then you will get the first Placement Properties dialog box. Also as PolyGeo mentioned, you can turn on Maplex in the ...
Mattropolis's user avatar
  • 1,674
5 votes

What is a simple script that can change the data frame name in an MXD?

Using info from DataFrame - to change data frame 'Data' to 'Layers': import arcpy arcpy.env.workspace = r"c:\temp" for mxd_file in arcpy.ListFiles(*.mxd): mxd = arcpy.mapping.MapDocument(mxd_file)...
Midavalo's user avatar
  • 29.8k
5 votes

Copy and paste of dataframe in ArcMap table of contents?

Another work-around until the bug is fixed is to start a second instance of ArcMap, then drag the data frame you with to copy into the new table of contents (thus creating a copy in the new map doc). ...
Dave's user avatar
  • 51
5 votes

How to pull a shapefile into R from PostGIS database (in Windows)?

At the University of Florida, David Bucklin and I have released a rpostgis package that provides bi-directional transfer between PostGIS and R for vector and raster data. The package does not rely on ...
Mathieu Basille's user avatar
5 votes
Accepted

Add Date to raster layers in raster stack in R

Adding a layer doesn't make sense because you are trying to associate a value with each layer, rather than creating a new NxM layer of values. Use setZ instead: dt<-as.data.frame( as.Date(c('...
Spacedman's user avatar
  • 65.1k
5 votes

Convert SpatialPoints to SpatialPointsDataFrame

Given x a SpatialPoints object: > x class : SpatialPoints features : 50 extent : 0.0006317429, 0.9926516, 0.02675848, 0.9901886 (xmin, xmax, ymin, ymax) coord. ref. : +init=epsg:...
Spacedman's user avatar
  • 65.1k
5 votes
Accepted

Convert SpatialPoints to SpatialPointsDataFrame

Use SpatialPointsDataFrame with data.frame to coerce into the desired object. library(sp) x <- SpatialPoints( rbind(c(1.5, 2), c(2.5, 2), c(0.5, 0.5), c(1, 0.25), c(1.5, ...
Jeffrey Evans's user avatar
5 votes
Accepted

Converting DataFrame with geometry column into GeoDataFrame in Pandas

Each of you geometries is within a list, so you are effectively passing a list of lists as a geometry to GeoDataFrame. You have to pass a list-like of geometries, not lists. Using apply you can get ...
martinfleis's user avatar
  • 2,447
5 votes

Appending DataFrame to existing layer in GeoPackage

You can read the geopackage file and append the dataframe and then re-write it: gdf_base = gpd.read_file("myfile.gpkg", layer='layer1') gdf_base = gdf_base.append(df,ignore_index=True) ...
Babak Fi Foo's user avatar
5 votes

Joining two Pandas DataFrames based on lat, long as fields

Another solution that was already mentioned by OP is to use the reverse geocoding. There might be a problem about that, the result quality will be strongly dependable on the decoder. Here the ...
Taras's user avatar
  • 33.3k
5 votes
Accepted

Intersection of two GeoPandas Dataframes

Unless you need the intersection geometries you dont need to intersect. You can use spatial join instead: import geopandas as gpd import numpy as np titre = gpd.read_file("/home/bera/Desktop/...
Bera's user avatar
  • 74.9k
4 votes

Copy and paste of dataframe in ArcMap table of contents?

You can do this from the Layout View using the following process: Select your data-frame in the layout view. Right-Click > Copy (or Ctrl+C) Right-Click > Paste (or Ctrl+V) Your data-frame will ...
Midavalo's user avatar
  • 29.8k
4 votes
Accepted

Legend from Multiple Data Frames

The easiest way that I've found to achieve this is to create an extra data frame, which is not visible on your finished map, but which contains all layers which are to be represented in your legend ...
Joshua A's user avatar
  • 557
4 votes

I want to do SpatialLines programatically

I am sure that one could write a function that would do this using lapply but I am not sure that it is worth the trouble. In this case, I am not sure that an apply like approach would buy you much. ...
Jeffrey Evans's user avatar
4 votes

Removing columns in a SpatialPolygonsDataFrame in R?

Here is one alternative using the select function from package dplyr: library(dplyr) SPDF@data <- SPDF@data %>% select(1, 3) #keeps column 1 and column 3 in the spdf object.
user3342735's user avatar
4 votes

Exporting each spatial bookmark to jpeg using arcpy gives IndexError?

My guess is that your data frame is not called 'test' so the call is returning an empty list. This answer explains a similar call in a bit more detail: https://gis.stackexchange.com/a/80237/43 If ...
Richard Morgan's user avatar
4 votes
Accepted

ArcPy - List layers and list fields in one code

import arcpy mxd = arcpy.mapping.MapDocument(r"CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] lyrList = arcpy.mapping.ListLayers(mxd, "", df) for lyr in lyrList: if lyr.supports("...
Kadir Şahbaz's user avatar
4 votes
Accepted

How to import raster from PostGIS into Python as dataframe

A bit convoluted, but this seems to work: import geopandas as gpd import pandas as pd import psycopg2 con = psycopg2.connect(database="somedbname", user="someuser", password="somepassword", host=...
Bera's user avatar
  • 74.9k
4 votes
Accepted

Dataframe object is not callable

As @user2856 stated, sample is a DataFrame, not a function, you can't call it. That's, you cannot use it with parenthesis, like sample(. Other problems arise because the whitespaces consist of tabs ...
Kadir Şahbaz's user avatar
4 votes

Reading .KML with GeoPandas

This solved my problem. I can see all features in the dataframe. I just changed the driver from KML to LIBKML gpd.io.file.fiona.drvsupport.supported_drivers['LIBKML'] = 'rw' fp=path_to_data+...
bravopapa's user avatar
  • 485
4 votes
Accepted

Creating GeoTIFF from Pandas DataFrame

Here is a possible solution: import numpy as np import pandas as pd import geopandas as gpd from geocube.api.core import make_geocube A = np.array([ [0.7626782059669495,-85.90831756591797,22....
swiss_knight's user avatar
  • 10.5k

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