我正在尝试根据Zillow自由发布的Shapefile数据确定某个位置的邻域.
我对Shapefile格式一无所知,并且在线查找教程时遇到了一些麻烦 - 但我基本上想要获取纬度/经度对,并针对Shapefile数据运行它以确定相应的邻域.
谁能指出我正确的方向?甚至不确定从哪里开始.
这是我抓住Shapefile文件的地方:http://www.zillow.com/howto/api/neighborhood-boundaries.htm
在这里的帖子的启发下,用R开发地理专题地图,我正在考虑构建一个基于邮政编码的等值区域图.我从http://www.census.gov/geo/www/cob/z52000.html下载了新罕布什尔州和缅因州的形状文件,但我有兴趣合并或合并这两个州的.shp文件.
maptools在使用中读取它们之后,包中是否有一种机制用于执行这种合并或串联两个.shp文件readShapeSpatial()?如果使用RgoogleMaps包装会更容易,也欢迎输入.
我在Java中编写了一个内核密度估计器,它以ESRI shapefile的形式输入并输出估计表面的GeoTIFF图像.为了测试这个模块,我需要一个示例shapefile,无论出于什么原因,我被告知要从R中包含的示例数据中检索一个.问题是没有任何示例数据是shapefile ...
所以我试图使用shapefiles包的convert.to.shapefile(4)函数将包含在R中的spatstat包中的bei数据集转换为shapefile.不幸的是,事实证明这比我想象的要难.有没有人有这方面的经验?如果你非常友好地帮助我,我会非常感激.
谢谢,瑞恩
我正在弄清楚如何在shape和多边形之间进行交点(空间连接).我的想法是获得最接近的点和那些在多边形内完全匹配的点.在ARGIS中,有一个名为CLOSEST的匹配选项函数,它们定义为:"最接近目标要素的连接要素中的要素是匹配的.两个或更多连接要素可能与目标的距离相同当出现这种情况时,随机选择一个连接特征作为匹配特征."
我有一个函数将点交叉成多边形,它是由Lyndon Estes在r-sig-geo列表中提供的,当所有多边形填满所有区域时代码工作得非常好.第二种情况称为空间连接距离,当match_option为CLOSEST时,在ArcGIS中称为INTERSECT,如ArcGIS所做的那样.因此,当区域未被所有多边形填充时,您可以修改点与多边形之间的最小距离.
这是第一个INTERSECT的数据和功能:
library(rgeos)
library(sp)
library(maptools)
library(rgdal)
library(sp)
xy.map <- readShapeSpatial("http://www.udec.cl/~jbustosm/points.shp")
manzana.map <- readShapeSpatial("http://www.udec.cl/~jbustosm/manzanas_from.shp" )
IntersectPtWithPoly <- function(x, y) {
# Extracts values from a SpatialPolygonDataFrame with SpatialPointsDataFrame, and appends table (similar to
# ArcGIS intersect)
# Args:
# x: SpatialPoints*Frame
# y: SpatialPolygonsDataFrame
# Returns:
# SpatialPointsDataFrame with appended table of polygon attributes
# Set up overlay with new column of join IDs in x
z <- overlay(y, x)
# Bind captured data to points dataframe
x2 <- …Run Code Online (Sandbox Code Playgroud) 我一直在尝试将绘图的内容(线/多边形)导出为我可以在ArcMap中打开的图层/ shapefile.这些是我一直使用的一些库,
Run Code Online (Sandbox Code Playgroud)library(shapefiles) library(PBSmapping) library(adehabitatHR) library(maptools) library(maps) library(rgdal) library(igraph)
我的纬度/经度数据如下所示:
Run Code Online (Sandbox Code Playgroud)tagdata<-read.table(text="meanlat meanlong -18.63327 147.0248 -18.6368 147.0238 -18.62068 147.294 -18.62953 147.2942 -18.62953 147.2942 -18.62091 147.2938 -18.62953 147.2942 -18.62466 147.2926 -18.73393 147.2816 -18.73393 147.2816 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541 -18.6368 147.0238 -18.63063 147.0256 -18.63063 147.0256 -18.68133 147.1164 -18.6368 147.0238 -18.63063 147.0256 -18.63063 147.0256 -18.75383 147.2541 -18.61273 147.0682 -18.69655 147.09 -18.6368 147.0238 -18.63063 147.0256 -18.63063 147.0256 -18.63217 147.0251 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541 -18.63063 147.0256 -18.68133 147.1164 -18.68133 147.1164 …
我有Eastings,Northings和Age的数据集.我想绘制数据集的年龄.数据集按以下方式上传:https://www.dropbox.com/s/zmtxluhwuupb9iv/age%20at%202100.csv
我用来创建简单图形和轮廓的代码如下:
age2100 <- read.csv("age at 2100.csv",header=TRUE, sep=",")
p <- ggplot(age2100, aes(x=Eastings, y=Northings, colour=("Age")))+geom_point()
p+geom_density2d()
Run Code Online (Sandbox Code Playgroud)
我得到的输出如下:
我无法上传图片,因此请在以下保管箱位置找到图片:
https://www.dropbox.com/s/5k5gefqi7wz6v36/age.png
现在,我想在背景上添加shapefile并将轮廓线剪切到shapefile.
所需的输出如下:
https://www.dropbox.com/s/tqhx2t8cqqozwbt/7Q10%20flow%20dye%20from%20P%20and%20S.JPG
如何从图1进入所需的输出?如果有人能给我建议,那就太好了.
非常感谢.
Jdbaba
我正在尝试使用包ggplot2中的fortify函数将空间对象转换为data.frame.但是我收到了一个错误.例如,遵循Hadley Wickhan的绘制多边形shapefile示例中使用的完全相同的代码,我键入以下命令行:
require("rgdal")
require("maptools")
require("ggplot2")
require("plyr")
utah = readOGR(dsn="/path/to/shapefile", layer="eco_l3_ut")
OGR data source with driver: ESRI Shapefile
Source: ".", layer: "eco_l3_ut"
with 10 features and 7 fields
Feature type: wkbPolygon with 2 dimensions
utah@data$id = rownames(utah@data)
Run Code Online (Sandbox Code Playgroud)
一切似乎都运作正常:
> str(utah)
..@ data :'data.frame': 10 obs. of 8 variables:
.. ..$ AREA : num [1:10] 1.42e+11 1.33e+11 3.10e+11 4.47e+10 1.26e+11 ...
.. ..$ PERIMETER : num [1:10] 4211300 3689180 4412500 2722190 3388270 ...
.. ..$ USECO_ : int [1:10] 164 …Run Code Online (Sandbox Code Playgroud) 我想使用imshow(例如)在一个国家的边界内显示一些数据(为了我的例子,我选择了美国)下面的简单例子说明了我想要的:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import RegularPolygon
data = np.arange(100).reshape(10, 10)
fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.imshow(data)
poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
ec='k', transform=ax.transAxes)
im.set_clip_path(poly)
ax.add_patch(poly)
ax.axis('off')
plt.show()
Run Code Online (Sandbox Code Playgroud)
结果是:

现在我想这样做但不是简单的多边形,我想使用美国的复杂形状.我已经创建了一些包含在"Z"数组中的示例数据,如下面的代码所示.我希望使用colourmap显示这些数据,但仅限于美国大陆的边界.
到目前为止,我已尝试过以下内容.我从一个形状文件这里包含在"nationp010g.shp.tar.gz"我用的底图模块在python绘制美国.请注意,这是我找到的唯一方法,它使我能够获得我需要的区域的多边形.如果有其他方法,我也会对它们感兴趣.然后我创建一个名为"mainpoly"的多边形,它几乎是我想要用蓝色着色的多边形:

请注意,只有一个物体被着色,所有其他不相交的多边形保持白色:

因此,蓝色区域几乎是我想要的,请注意加拿大附近有不必要的边界线,因为边界实际上穿过了一些湖泊,但这是一个小问题.真正的问题是,为什么我的imshow数据不在美国境内显示?比较我的第一个和第二个示例代码,我无法理解为什么我在第二个示例中没有得到修剪的imshow,就像我在第一个示例中所做的那样.在理解我所缺少的内容时,我们将不胜感激.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap as Basemap
from matplotlib.patches import Polygon
# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119,llcrnrlat=22,urcrnrlon=-64,urcrnrlat=49,
projection='lcc',lat_1=33,lat_2=45,lon_0=-95)
shp_info = m.readshapefile('nationp010g/nationp010g', …Run Code Online (Sandbox Code Playgroud) 我正在使用PHPShapefile库来生成KML并将数据显示到谷歌地图,但是当涉及到"点"形状时它不起作用而不生成KML.这是Polygon形状的代码片段,帮助我为Point形状创建.
//this shape data i'm fetching from shapefile library.
$shp_data = $record->getShpData();
if (isset($shp_data['parts'])) {
$counter1 = 0;
if ($shp_data['numparts']) {
$polygon_array['polygon']['status'] = 'multi-polygon';
} else {
$polygon_array['polygon']['status'] = 'single-polygon';
}
$polygon_array['polygon']['total_polygon'] = $shp_data['numparts'];
foreach ($shp_data['parts'] as $polygon) {
foreach ($polygon as $points) {
$counter = 0;
$polygon_string = '';
while ($counter < count($points)) {
if ($counter == 0) {
$polygon_string = $points[count($points) - 1]['x'] . ',';
$polygon_string .= $points[$counter]['y'] . ' ' . $points[$counter]['x'] . ',';
} …Run Code Online (Sandbox Code Playgroud) 我想为特定地理区域中的H3六角形生成shapefile 。特别是,我对分辨率为6、7和9的海湾地区感兴趣。如何为覆盖该区域的六边形创建shapefile?
我是shapefile或任何其他地理数据结构的新手。我对python和R最满意。