Closed giantchen2012 closed 6 years ago
OK, I finally get the exact error Postgis Plugin: ERROR: relation "***" does not exist
but it's still hard to resolve, i'm not in the situation as others https://github.com/mapnik/mapnik/issues/3898
Can you please post the exact SQL query and error message?
I just init the postgis datasource as shown in the code, and the SQL:select * from ‘mytable’ limit 0. it's a statement in postgis_datasource.cpp:
std::ostringstream s;
s << "SELECT * FROM " << populate_tokens(table_) << " LIMIT 0";
shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
and more, I build my mapnik 3.0.20 with libpq 9.4.5 with VS 2017 and toolset v141. But my postgresql version is 9.6, should I build it with the libpq.dll under postgresql 9.6?
this is what I did in my command line:
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
>>> mapnik.PostGIS(database="postgis_24_sample",user="postgres",password="the-password",table="shorelines",extent="-180,-90,180,90",geometry_field="outline",srid=4326)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dir\to\mapnik\__init__.py", line 458, in PostGIS
return CreateDatasource(keywords)
RuntimeError: Postgis Plugin: 错误: 关系 "shorelines" 不存在
LINE 1: SELECT * FROM shorelines LIMIT 0
^
in executeQuery Full sql was: 'SELECT * FROM shorelines LIMIT 0'
Well, and I try to load from xml, it works fine. the code:
import mapnik
m = mapnik.Map(256,256)
mapnik.load_map(m, "path/to/file.xml")
m.zoom_all()
mapnik.render_to_file(m, "the_image.png")
and my xml
<Map background-color="blue" srs="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs">
<Style name="My Style">
<Rule>
<PolygonSymbolizer fill="#f2eff9" />
<LineSymbolizer stroke="rgb(50%,50%,50%)" stroke-width="0.1" />
</Rule>
</Style>
<Layer name="world" srs="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">postgis</Parameter>
<Parameter name="host">localhost</Parameter>
<Parameter name="dbname">postgis_24_sample</Parameter>
<Parameter name="user">postgres</Parameter>
<Parameter name="password">my password</Parameter>
<Parameter name="table">"shorelines"</Parameter>
<Parameter name="estimate_extent">true</Parameter>
</Datasource>
</Layer>
</Map>
I don't understand why do you have quotations marks in
<Parameter name="table">"shorelines"</Parameter>
Does it work also without the quotation marks?
Ok, i find some thread from this article, so I add the quotation marks. And now, my question is: Why mapnik python cant create the datasource directly by code, but works correctly loading xml map?
I've tried to call mapnik.PostGIS()
as you did and had to use dbname="..."
instead of database="..."
.
Great appreciation!! @talaj , i've tried what you adviced, yep, it works fine. So the problem is that I used the wrong param's name.
Hi, folks, I've encounter a problem similar to this issue, but my problem is more specific. I use Mapnik 2.2.0 to generate map, but it ends with runtime error, the error message is in chaos for my locale. And the SQL output in the command line is the same with isses/70. any help will be appreciated.
My code was like this:
This piece of code is example code from Chapter 9 in Python Geospatial Development 3rd edition written by Erik Westra, published in 2016 by Packet