标签: shapefile

Python和Shapefile:导入shapefile后坐标非常大

我下载了波士顿的形状文件,并想使用下面的代码将其绘制出来。然而它给了我一个错误ValueError: lat_0 must be between -90.000000 and 90.000000 degrees

原来coords是有值的(33869.92130000144, 777617.2998000011, 330800.31099999696, 959741.1853)为什么这么大?

波士顿形状文件在此处获取

代码

# Import Boston shapefile
shapefilename = 'ZIPCODES_NT_POLY'
shp = fiona.open(shapefilename + '.shp')
coords = shp.bounds
shp.close()

w, h = coords[2] - coords[0], coords[3] - coords[1]
extra = 0.01

m = Basemap(
    projection='tmerc', ellps='WGS84',
    lon_0 = np.mean([coords[0], coords[2]]), 
    lat_0 = np.mean([coords[1], coords[3]]), 
    llcrnrlon = coords[0] - extra * w,
    llcrnrlat = coords[1] - extra * h,
    urcrnrlon = coords[2] + extra …
Run Code Online (Sandbox Code Playgroud)

python gis shapefile python-2.7 matplotlib-basemap

2
推荐指数
1
解决办法
2278
查看次数

DotSpatial shapefile 的性能非常慢

我正在尝试从特定形状文件中读取所有特征数据。在本例中,我使用 DotSpatial 打开文件,并迭代这些功能。这个特定的 shapefile 文件大小仅为 9mb,dbf 文件大小为 14mb。大约有 75k 个特征需要循环。

请注意,这一切都是通过控制台应用程序以编程方式进行的,因此不涉及渲染或任何操作。

加载形状文件时,我重新投影,然后进行迭代。加载和重新投影非常快。然而,一旦代码到达我的 foreach 块,就需要将近 2 分钟来加载数据,并且在 VisualStudio 中调试时使用大约 2GB 内存。对于相当小的数据文件来说,这似乎非常非常过分。

我已经在 Visual Studio 之外从命令行运行了相同的代码,但是时间仍然大约是 2 分钟,并且该进程需要大约 1.3GB 的内存。

有什么办法可以加快速度吗?

下面是我的代码:

// Load the shape file and project to GDA94
Shapefile indexMapFile = Shapefile.OpenFile(shapeFilePath);
indexMapFile.Reproject(KnownCoordinateSystems.Geographic.Australia.GeocentricDatumofAustralia1994);

// Get's slow here and takes forever to get to the first item
foreach(IFeature feature in indexMapFile.Features)
{
    // Once inside the loop, it's blazingly quick.
}
Run Code Online (Sandbox Code Playgroud)

有趣的是,当我使用VS立即窗口时,它超级超级快,完全没有延迟......

c# shapefile dotspatial

2
推荐指数
1
解决办法
3835
查看次数

给定美国的地理坐标,如何确定它是在城市还是农村地区?

给定美国的地理坐标,如何确定它是在城市还是农村地区?

我有大约10000个地理坐标,全部在美国,我想使用Python +底图来找出一个点是城市还是乡村。

我不确定要使用哪个库或形状文件。

我需要一个这样的函数:

def is_urban(coordinate):
  # use the shapefile
  urban = False
  return urban
Run Code Online (Sandbox Code Playgroud)

geospatial shapefile shapely pyshp

2
推荐指数
1
解决办法
1467
查看次数

将光栅裁剪为 R 中矢量 (.shp) 的精确轮廓?

我想将光栅图层精确地剪切到 R 中 shpfile 的轮廓。

  crop_rast      = crop (raster , extent(vector))                 # Crop
  mask_rast      = mask (crop_rast, vector)                       # Mask
Run Code Online (Sandbox Code Playgroud)

这是行不通的。

r shapefile r-raster

2
推荐指数
1
解决办法
3955
查看次数

生成美国的随机坐标?

我想生成美国(包括夏威夷和阿拉斯加)的一组随机纬度和经度坐标。我尝试使用国家气象局 ( https://www.weather.gov/gis/USstates )的 shapefile,但它在海洋中央生成点。这样做的最佳方法是什么?我考虑过在美国内陆定义自己的多边形,但这会排除某些州。我\xe2\x80\x99也看到了其他类似的问题,他们使用了美国城市的CSV列表,但我\xe2\x80\x99d宁愿它是完全随机的。

\n

python geocoding shapefile coordinates

2
推荐指数
1
解决办法
897
查看次数

从 shapefile 中获取更多聚合形状

如上一个问题所述,我正在绘制德国邮政编码。最精细的级别是 5 位数字,例如 10117。我想绘制在两位数字级别上定义的边界,同时还保持邮政编码的着色粒度。

这里又是我的代码的第一部分,用于对邮政编码进行着色:

# for loading our data
library(raster)
library(readr)
library(readxl)
library(sf)
library(dplyr)

# for datasets
library(maps)
library(spData)

# for plotting
library(grid)
library(tmap)
library(viridis)
Run Code Online (Sandbox Code Playgroud)

获取德国的形状文件(链接)。在德国,邮政编码称为 Postleitzahlen (PLZ)。

germany <- read_sf("data/OSM_PLZ.shp")
Run Code Online (Sandbox Code Playgroud)

将 PLZ 分为任意组以进行绘图。

germany <- germany %>% 
  mutate(plz_groups = case_when(
    substr(plz, 1, 1) == "1" ~ "Group A",
    substr(plz, 2, 2) == "2" ~ "Group B",    
    TRUE ~ "Group X" # rest
  ))
Run Code Online (Sandbox Code Playgroud)

由PLZ进行绘图填充:

tm_shape(germany) +
  tm_fill(col = "plz_groups") 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想划定的界限如下:

在此输入图像描述

我在另一篇文章的答案的基础上设法绘制了德国的国家边界。但为此我使用了不同的形状文件。我还没有找到符合我正在寻找的级别的现有形状文件。

我可以使用已有的粒度 shapefile 并以某种方式聚合到 2 …

mapping r shapefile tmap r-sf

2
推荐指数
1
解决办法
132
查看次数

在MySQL Geometry数据类型列中查询数据

我有一个表存储GEOMETRY数据类型列中的多边形,我使用ogr2​​ogr通过shapefile加载.这是create语句:

CREATE TABLE IF NOT EXISTS `sunzones` (
  `OGR_FID` int(11) NOT NULL AUTO_INCREMENT,
  `polygon` geometry NOT NULL,
  UNIQUE KEY `OGR_FID` (`OGR_FID`),
  SPATIAL KEY `polygon` (`polygon`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=105 ;
Run Code Online (Sandbox Code Playgroud)

这是一个示例记录:

POLYGON((449455.354522821 2447255.57758461,449700.419971925 2447132.08575524,449970.797988416 2447012.08302579,450331.302189915 2446845.08750142,450720.557402377 2446631.12366577,451001.686314893 2446471.65633497,451351.253709065 2446236.2071619,451621.320850174 2445889.34918971,451822.94912776 2445643.44939179,451970.329536186 2445268.16443891,451900.90187755 2444641.13680345,451762.850153972 2443964.1640728,451483.986510987 2443208.22160261,451201.806260121 2442650.10616671,451020.687327243 2442095.95148262,450839.505763005 2441544.78980207,450683.636511575 2441015.10597334,450538.454805135 2440413.89081544,450433.333155727 2440035.55620047,450360.648999258 2439678.70563045,450288.151292623 2439419.31682052,450118.029551282 2439008.99974342,449901.03211162 2438634.67295293,449702.407549484 2438469.26337817,449341.345080443 2438239.89817619,449070.656839706 2438139.47157292,448886.71805136 2438143.99566917,448634.339635752 2438227.50240038,448385.707435195 2438433.96784289,448234.638650137 2438747.88628722,448145.380437968 2439372.19635416,448095.562049752 2439852.04892374,447984.553987549 2440439.87931978,447808.669818343 2441024.70524153,447592.724965448 2441364.09711298,447275.840595988 2441754.49255107,447067.208249397 2442148.36776757,446617.319564483 2442841.67896542,446426.750106166 2443289.53943803,446257.992375297 2443841.82345023,446157.983746886 2444530.46142231,446014.475379242 2445071.69774818,445881.655839275 2445515.48887139,445748.650167696 2445843.84709753,445669.894930651 2446244.64998972,445684.828488262 2446608.40816774,445779.199887883 2446997.59260231,445887.760935538 …
Run Code Online (Sandbox Code Playgroud)

mysql gis geometry shapefile

1
推荐指数
1
解决办法
6255
查看次数

尝试将.csv合并到.shp文件时,R-多边形撕裂

我正在尝试将.csv文件中每个国家('prop')的数据与.shp文件中的每个对应多边形相关联,但是,尝试该merge功能后,这些多边形无法正确映射。

首先,我使用fortify.shp文件中的3个字母的国家/地区代码来创建多边形。

gpclibPermit()
worldmapDf<- fortify(worldmap, region="ISO_3_CODE")
Run Code Online (Sandbox Code Playgroud)

然后,我尝试关联.csv文件中的“ prop”数据,并通过3个字母的国家/地区代码列(在这种情况下为“ code”)进行匹配。

forestareamap <- merge(worldmapDf, forestarea, by.x="id", by.y="code")
Run Code Online (Sandbox Code Playgroud)

然后我尝试绘制它...

ggplot(forestareamap)+aes(long,lat,group=group,fill=prop)+geom_polygon()
Run Code Online (Sandbox Code Playgroud)

这发生了...

在此处输入图片说明

显然,多边形的绘制顺序不正确,但是我不确定如何正确地对其进行排序。

在设防后直接绘制数据会生成正确的多边形,因此合并功能会出现问题。作为一个完整的新秀,我不知道...

merge r polygon shapefile

1
推荐指数
1
解决办法
445
查看次数

形状文件,prisecroads,邻接两个州

使用R和两个形状文件:tl_2015_01_prisecroads(alabama)和tl_2015_13_prisecroads georgia),使用readOGR()读取两个R对象.我需要关注一个包括西乔治亚州和东阿拉巴马州的地区.我试过rbind()和spRbind()无济于事.

ga_al <- rbind(alabama, georgia, fix.duplicated.IDs=TRUE)
  Error in as(x, "SpatialLines") : 
  no method or default for coercing “logical” to “SpatialLines”

ga_al <- spRbind(alabama, georgia)
  Error in spRbind(as(obj, "SpatialLines"), as(x, "SpatialLines")) : 
  non-unique line IDs
Run Code Online (Sandbox Code Playgroud)

问题1:如何组合两个形状文件来映射两个状态的区域?问题2:如何放大组合形状文件的较小区域?

gis r esri shapefile

1
推荐指数
1
解决办法
237
查看次数

将Lat/Lon点映射到R中的形状文件

我试图使用shapefile识别每组lat/lon坐标的邮政编码.

Lat Lon数据摘自:https://data.cityofchicago.org/Public-Safety/Crimes-2017/d62x-nvdr(Crimes _-_ 2001_to_present.csv)

Shapefile:https: //www2.census.gov/geo/tiger/PREVGENZ/zt/z500shp/zt17_d00.shp(伊利诺伊州的邮政编码定义)

library(rgeos)
library(maptools)

ccs<-read.csv("Crimes_-_2001_to_present.csv")
zip.map <- readOGR("zt17_d00.shp")
latlon<-ccs[,c(20,21)]
str(latlon)
   'data.frame':   6411517 obs. of  2 variables:
    $ Latitude : num  42 41.7 41.9 41.8 42 ...
    $ Longitude: num  -87.7 -87.6 -87.7 -87.6 -87.7 ...
coordinates(latlon) = ~Longitude+Latitude
write.csv(cbind(latlon,over(zip.map,latlon)),"zip.match.csv")
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

(函数(classes,fdef,mtable)中的错误:无法为签名'"SpatialPolygonsDataFrame","data.frame"找到函数'over'的继承方法

我错过了什么?任何帮助表示赞赏!

geocoding r geospatial shapefile latitude-longitude

1
推荐指数
1
解决办法
2635
查看次数