更新:
是的,就是这样!
像mloskot说的那样,需要倾倒整个表格.使用sql选择字段会丢失有关fuield宽度的信息.
谢谢,修好了!
大家好,
我有ogr2ogr的问题.我正在尝试将PostgreSQL表格转储到Shapefile.ogr2ogr似乎改变了整数和char等数据类型的大小.
以下是Shapefile集读入的DB结构的一部分:
Table "test"
nd_1 - numeric(8,0)
nd_2 - numeric(2,0)
nd_3 - numeric(2,0)
nd_9 - character varying(60)
Run Code Online (Sandbox Code Playgroud)
它看起来正确.
这是有趣的开始:
ogr2ogr air5000.shp "PG: [...]" sql 'select
CAST(nd_1 AS INTEGER),
CAST(nd_2 AS INTEGER),
CAST(nd_3 as INTEGER),
CAST(ND_9 AS CHARACTER VARYING(60))
from test' ;
Run Code Online (Sandbox Code Playgroud)
然后
dbview -e test.dbf
Field Name Type Length Decimal Pos
nd 1 - N - 11 - 0
nd 2 - N - 11 - 0
nd 3 - N - 11 …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用GIS编程.我想建立一个带有地图的简单网站.所以,我选择C#和SharpMap作为地图库.一切正常,直到我从形状文件添加许多图层.我添加的最后一层是我看到的唯一一层.这是我的代码的一部分:
SharpMap.Map map = new SharpMap.Map(outputsize);
SharpMap.Layers.VectorLayer layCountry = new SharpMap.Layers.VectorLayer("nuoc");
layCountry.DataSource = new SharpMap.Data.Providers.ShapeFile(@"D:\code\SharpMapDemo\SharpmapDemo\App_data\vn_tinh_region.shp", false);
layCountry.Style.Fill = new SolidBrush(Color.Yellow);
layCountry.Style.Outline = new Pen(Color.Black, 1);
layCountry.Enabled = true;
layCountry.Style.EnableOutline = true;
SharpMap.Layers.VectorLayer newLay = new SharpMap.Layers.VectorLayer("tinh");
newLay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"D:\code\SharpMapDemo\SharpmapDemo\App_Data\5tinh_region.shp", false);
newLay.Style.Fill = new SolidBrush(Color.Red);
newLay.Style.Outline = new Pen(Color.Black, 1);
newLay.Style.EnableOutline = true;
map.Layers.Add(newLay);
map.Layers.Add(layCountry);
Run Code Online (Sandbox Code Playgroud)
所以layCountry是我唯一看到的人.当我将最后两行更改为:
map.Layers.Add(layCountry);
map.Layers.Add(newLay);
Run Code Online (Sandbox Code Playgroud)
newLay是唯一的一个.任何帮助都很感激.感谢您阅读此内容并抱歉我的英语不好.
我有一个基于非重叠面的多边形shapefile (.shp),具有较大的空间范围和许多关联的属性。shapefile投影在UTM中。我想将多边形转换为在30-m分辨率网格中间隔开的点,其中每个点将保留其位于其中的多边形的属性。
输出将只是要点表:
X, Y, attribute1, attribute2, attribute 3,etc...
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想在R或(较不理想)我可以在Mac上运行的其他一些免费程序中执行此操作。
shapefile"Property1A"的数据集是:
df
# suburb area asst
# 0 Te Aro 14.541780 R076
# 1 Te Aro 7.655428 R076
# 2 Te Aro 3189.976134 <NA>
# 3 Te Aro 242.173386 0132
# 4 Karori 537.697290 R003
# 5 Pipitea 1116.954993 R105
# 6 Mt Cook 106.099900 R151
# 7 Te Aro 83.307421 R057
# 8 Aro Valley 544.665788 R105
# 9 Aro Valley 59.726882 R110
Run Code Online (Sandbox Code Playgroud)
当我尝试为郊区"Te Aro"子集shapefile时,我使用的代码是:
TeAro <- subset(Property1A, suburb == "Te Aro")
Run Code Online (Sandbox Code Playgroud)
但是有一个错误:
TeAro <- subset(Property1A, suburb == "Te …Run Code Online (Sandbox Code Playgroud) 我正努力在谷歌地图上叠加邻居边界.我正在尝试遵循此代码.我的版本如下.你看到什么明显错了吗?
#I set the working directory just before this...
chicago = readOGR(dsn=".", layer="CommAreas")
overlay <- spTransform(chicago,CRS("+proj=longlat +datum=WGS84"))
overlay <- fortify(overlay)
location <- unlist(geocode('4135 S Morgan St, Chicago, IL 60609'))+c(0,.02)
ggmap(get_map(location=location,zoom = 10, maptype = "terrain", source = "google",col="bw")) +
geom_polygon(aes(x=long, y=lat, group=group), data=overlay, alpha=0)+
geom_path(color="red")
Run Code Online (Sandbox Code Playgroud)
任何见解都会非常感激.感谢您的帮助和耐心.
我有一个由各个州组成的美国多边形图形文件,作为其属性值。此外,我还有一些数组,用于存储我也感兴趣的点事件的纬度和经度值。从本质上讲,我想“空间连接”点和面(或执行检查以查看每个面和面[即状态])点),然后求和每个州的点数,找出哪个州的“事件”数最多。
我相信伪代码将是这样的:
Read in US.shp
Read in lat/lon points of events
Loop through each state in the shapefile and find number of points in each state
print 'Here is a list of the number of points in each state: '
Run Code Online (Sandbox Code Playgroud)
任何库或语法将不胜感激。
根据我的判断,OGR库是我所需要的,但是我在语法上遇到了麻烦:
dsPolygons = ogr.Open('US.shp')
polygonsLayer = dsPolygons.GetLayer()
#Iterating all the polygons
polygonFeature = polygonsLayer.GetNextFeature()
k=0
while polygonFeature:
k = k + 1
print "processing " + polygonFeature.GetField("STATE") + "-" + str(k) + " of " + str(polygonsLayer.GetFeatureCount())
geometry = …Run Code Online (Sandbox Code Playgroud) 我试图通过Gdal ogr2ogr将shapefile插入到PostgreSQL中,命令如下所示:
ogr2ogr -f 'PostgreSQL' PG:dbname='dbname',user='user',host='172.17.2.176',password='password',port='5432' shapefile -nln 'cities'
但是,ogr2ogr似乎无法连接到位于单独的docker容器中的PosgreSQL.所有连接参数都是正确的,其他连接成功地使用相同的连接参数并执行到同一个PostgreSQL容器.Laravel迁移,在对这些表执行命令之前检查数据库和表是否存在的命令行sql,以及使用COPY命令导入csv文件,都使用ogr2ogr命令中使用的相同连接参数成功运行到单独的PostgreSQL docker容器.
当我跑:
ogrinfo 'PostgreSQL' PG:dbname='dbname',user='user',host='172.17.2.176',password='password',port='5432'
我收到一个错误:"无法使用以下驱动程序打开数据源`PostgreSQL'..."
列出的其中一个驱动程序是" - > PostgreSQL"
这意味着PostgreSQL驱动程序已加载并启用?< - 一点混乱
与之连接的用户具有超级用户权限,由官方PostgreSQL docker镜像中的.sh脚本创建:https://github.com/docker-library/postgres/tree/master/9.4
据我所知,通过我对谷歌和文档的研究发现,一切都是正确的,应该正常工作..
超级用户权限,数据库连接的正确语法,驱动程序加载..我错过了什么?我一直试图让这项工作工作几天,我需要帮助.
如何使用来自contour()x,y和z数据的输出来制作轮廓线的shapefile,以输出到ArcMap?
我想知道是否有人建造了世界各大洲的栅格,每个细胞等于细胞与最近岸的距离.该地图将突出显示内陆最孤立的陆地区域.
我想这只是rasterize一个全局边界的shapefile,然后计算距离.