14
votes
Accepted
Getting index of active data frame in ArcPy?
I think you're over-thinking this: mxd.activeDataFrame will give you the data frame itself, no need to get the name of it and then go searching for an index number. Check out the MapDocument ...
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 ...
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.
...
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, ...
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 ...
8
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 ...
8
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)
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])
8
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(&...
7
votes
Copy and paste of dataframe in ArcMap table of contents?
Unfortunately, you've run into BUG-000088466, in which you can't copy and paste a data frame in ArcGIS 10.3.1. The suggested workaround is what @KFP said: copy and paste your layers into a new data ...
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
...
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 ...
6
votes
How to join a table to a shapefile with non-matching IDs and names (similar strings)?
I want to add some details to Farid Cher's answer as this is a very common problem. Using amatch can do wonders, but with these Spatial objects you should not use base::merge and not access the @data ...
6
votes
Accepted
How to join a table to a shapefile with non-matching IDs and names (similar strings)?
I would go for stringdist package which has implemented many algorithms to calculate the partial similarity (distance) of strings including Jaro-winkler.
Here is a fast solution for you:
#df to be ...
5
votes
Accepted
Is there a way to turn a data frame off in ArcMap 10.2?
On/off doesn't appear to be an option with a data frame. Moving the frame off the document would work with elementPositionX and elementPositionY. Shrinking the frame to zero is an option as well.
...
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 ...
5
votes
Accepted
Error when trying to subset a vector to a dataframe
Try
library(rgdal)
library(ggplot2)
library(rgeos)
library(maptools)
library(plyr)
library(raster)
#read in shapefile
eth <- getData("GADM", country = "Ethiopia", level = 1)
#fortify
eth@data$...
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). ...
5
votes
Accepted
Converting Map Coordinates to Layout Coordinates in rotated Dataframe?
Original layout:
Script:
import arcpy, os, traceback, sys,time
import numpy as np
from math import radians,sin,cos
try:
def showPyMessage():
arcpy.AddMessage(str(time.ctime()) + " - " + ...
5
votes
Converting Map Coordinates to Layout Coordinates in rotated Dataframe?
Here is a tested solution:
Install comtypes and snippet102 (How do I access ArcObjects from Python?) with your python installation
use the following python function (based on comtypes). Make sure ...
5
votes
Accepted
Limiting imagery displayed to non-rectangular area using ArcGIS Desktop?
If you want to clip for cartographic reasons and do not want to generate a clipped raster, you may do this via Data Frame Properties if your grid layer is a polygon.
Data Frame Properties>Data ...
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)...
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('...
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:...
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, ...
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 ...
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 ...
4
votes
Accepted
How to remove layers that are not in visible df extent
The Extent object supports a 'disjoint' (i.e. does not intersect) method.
Try something like:
for mxdname in arcpy.ListFiles('*.mxd'):
print mxdname
mxd = arcpy.mapping.MapDocument(os....
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 ...
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.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
data-frame × 164arcgis-desktop × 51
r × 43
arcpy × 37
arcmap × 32
python × 23
coordinate-system × 12
geopandas × 12
raster × 10
pandas × 10
layouts × 9
shapefile × 8
polygon × 8
arcgis-10.2 × 8
layers × 8
arcgis-10.1 × 7
arcgis-10.3 × 7
data-driven-pages × 6
export × 5
convert × 5
geodataframe × 5
arcgis-10.0 × 4
labeling × 4
clip × 4
extents × 4