Merge remote-tracking branch 'origin/master'

This commit is contained in:
Artem Pavlenko 2011-12-17 11:45:08 +00:00
commit 365e42cd0e
23 changed files with 274 additions and 124 deletions

View file

@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
Mapnik 2.1.0
------------
- SQLite - Added support for !intersects! token in sql subselects (#809) allow custom positioning of rtree spatial filter.
- New CSV plugin - reads tabular files - autodetecting geo columns, newlines, and delimiters. Uses in-memory featureset for fast rendering and is not designed for large files (#902)
- Fixed bug in shield line placement when dx/dy are used to shift the label relative to the placement point (Matt Amos) (#908)

View file

@ -12,6 +12,7 @@ clean:
reset:
if test -e ".sconf_temp/"; then rm -r ".sconf_temp/"; fi
if test -e ".sconsign.dblite"; then rm ".sconsign.dblite"; fi
if test -e "config.cache"; then rm "config.cache"; fi
uninstall:
python scons/scons.py uninstall

View file

@ -142,7 +142,11 @@ paths += "__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n"
if not os.path.exists('mapnik'):
os.mkdir('mapnik')
file('mapnik/paths.py','w').write(paths % (os.path.relpath(env['MAPNIK_LIB_DIR'],target_path)))
if hasattr(os.path,'relpath'): # python 2.6 and above
file('mapnik/paths.py','w').write(paths % (os.path.relpath(env['MAPNIK_LIB_DIR'],target_path)))
else:
file('mapnik/paths.py','w').write(paths % (env['MAPNIK_LIB_DIR']))
# force open perms temporarily so that `sudo scons install`
# does not later break simple non-install non-sudo rebuild

View file

@ -593,7 +593,7 @@ class PDFPrinter:
for l in m.layers:
# extract the layer names for naming layers if we use OCG
self._layer_names.append(l.title or l.name)
self._layer_names.append(l.name)
layer_map = Map(m.width,m.height,m.srs)
layer_map.layers.append(l)
@ -884,7 +884,7 @@ class PDFPrinter:
for l in reversed(m.layers):
have_layer_header = False
added_styles={}
layer_title = l.title or l.name
layer_title = l.name
if layer_title in processed_layers:
continue
processed_layers.append(layer_title)
@ -906,8 +906,8 @@ class PDFPrinter:
if r.filter and str(r.filter) != "true":
if len(rule_text) > 0:
rule_text += " AND "
if r.title:
rule_text += r.title
if r.name:
rule_text += r.name
else:
rule_text += str(r.filter)
active_rules = tuple(active_rules)

View file

@ -42,8 +42,9 @@ bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom)
{
typedef std::back_insert_iterator<std::string> sink_type;
sink_type sink(wkt);
wkt_generator<sink_type> generator(true);
bool result = karma::generate(sink, generator, geom);
// disable temporarily until compile works with g++
//wkt_generator<sink_type> generator(true);
bool result = false;//karma::generate(sink, generator, geom);
return result;
}
@ -51,8 +52,9 @@ bool to_wkt(std::string & wkt, mapnik::geometry_container const& geom)
{
typedef std::back_insert_iterator<std::string> sink_type;
sink_type sink(wkt);
wkt_multi_generator<sink_type> generator;
bool result = karma::generate(sink, generator, geom);
// disable temporarily until compile works with g++
//wkt_multi_generator<sink_type> generator;
bool result = false;//karma::generate(sink, generator, geom);
return result;
}

View file

@ -68,7 +68,7 @@ struct get_type
int operator() (geometry_type const& geom) const
{
return (int)geom.type();
return static_cast<int>(geom.type());
}
};

View file

@ -62,6 +62,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
key_field_(*params_.get<std::string>("key_field", "")),
row_offset_(*params_.get<int>("row_offset", 0)),
row_limit_(*params_.get<int>("row_limit", 0)),
intersects_token_("!intersects!"),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
format_(mapnik::wkbAuto)
{
@ -185,7 +186,8 @@ void sqlite_datasource::bind() const
if (using_subquery_)
{
std::ostringstream s;
s << "SELECT " << fields_ << " FROM (" << table_ << ") LIMIT 1";
std::string query = populate_tokens(table_);
s << "SELECT " << fields_ << " FROM (" << query << ") LIMIT 1";
found_types_via_subquery = sqlite_utils::detect_types_from_subquery(s.str(),geometry_field_,desc_,dataset_);
}
@ -224,7 +226,12 @@ void sqlite_datasource::bind() const
if (geometry_field_.empty())
{
throw datasource_exception("Sqlite Plugin: cannot detect geometry_field, please supply the name of the geometry_field to use.");
std::ostringstream s;
s << "Sqlite Plugin: unable to detect the column "
<< "containing a valid geometry on table '" << geometry_table_ << "'. "
<< "Please provide a column name by passing the 'geometry_field' option "
<< "or indicate a different spatial table to use by passing the 'geometry_table' option";
throw datasource_exception(s.str());
}
if (index_table_.empty())
@ -301,6 +308,7 @@ void sqlite_datasource::bind() const
{
// TODO - clean this up - reducing arguments
std::string query = populate_tokens(table_);
if (!sqlite_utils::detect_extent(dataset_,
has_spatial_index_,
extent_,
@ -309,7 +317,7 @@ void sqlite_datasource::bind() const
geometry_field_,
geometry_table_,
key_field_,
table_))
query))
{
std::ostringstream s;
s << "Sqlite Plugin: extent could not be determined for table '"
@ -323,6 +331,17 @@ void sqlite_datasource::bind() const
is_bound_ = true;
}
std::string sqlite_datasource::populate_tokens(const std::string& sql) const
{
std::string populated_sql = sql;
if (boost::algorithm::ifind_first(populated_sql, intersects_token_))
{
// replace with dummy comparison that is true
boost::algorithm::ireplace_first(populated_sql, intersects_token_, "1=1");
}
return populated_sql;
}
sqlite_datasource::~sqlite_datasource()
{
}
@ -460,23 +479,21 @@ featureset_ptr sqlite_datasource::features(query const& q) const
s << " FROM ";
std::string query (table_);
std::string query(table_);
if (! key_field_.empty() && has_spatial_index_)
{
std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16);
spatial_sql << " WHERE " << key_field_ << " IN (SELECT pkid FROM " << index_table_;
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
if (boost::algorithm::ifind_first(query, "WHERE"))
{
boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND ");
}
else if (boost::algorithm::ifind_first(query, geometry_table_))
{
boost::algorithm::ireplace_first(query, table_, table_ + " " + spatial_sql.str());
}
// TODO - debug warn if fails
sqlite_utils::apply_spatial_filter(query,
e,
table_,
key_field_,
index_table_,
geometry_table_,
intersects_token_); }
else
{
query = populate_tokens(table_);
}
s << query ;
@ -539,19 +556,18 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
if (! key_field_.empty() && has_spatial_index_)
{
std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16);
spatial_sql << " WHERE " << key_field_ << " IN (SELECT pkid FROM " << index_table_;
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
if (boost::algorithm::ifind_first(query, "WHERE"))
{
boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND ");
}
else if (boost::algorithm::ifind_first(query, geometry_table_))
{
boost::algorithm::ireplace_first(query, table_, table_ + " " + spatial_sql.str());
}
// TODO - debug warn if fails
sqlite_utils::apply_spatial_filter(query,
e,
table_,
key_field_,
index_table_,
geometry_table_,
intersects_token_);
}
else
{
query = populate_tokens(table_);
}
s << query ;

View file

@ -70,6 +70,8 @@ private:
mutable std::string key_field_;
mutable int row_offset_;
mutable int row_limit_;
// TODO - also add to postgis.input
const std::string intersects_token_;
mutable mapnik::layer_descriptor desc_;
mutable mapnik::wkbFormat format_;
mutable bool use_spatial_index_;
@ -80,6 +82,7 @@ private:
// Fill init_statements with any statements
// needed to attach auxillary databases
void parse_attachdb(std::string const& attachdb) const;
std::string populate_tokens(const std::string& sql) const;
};
#endif // MAPNIK_SQLITE_DATASOURCE_HPP

View file

@ -108,6 +108,42 @@ public:
//}
}
static bool apply_spatial_filter(std::string & query,
mapnik::box2d<double> const& e,
std::string const& table,
std::string const& key_field,
std::string const& index_table,
std::string const& geometry_table,
std::string const& intersects_token)
{
std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16);
spatial_sql << key_field << " IN (SELECT pkid FROM " << index_table;
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
if (boost::algorithm::ifind_first(query, intersects_token))
{
boost::algorithm::ireplace_all(query, intersects_token, spatial_sql.str());
return true;
}
// substitute first WHERE found if not using JOIN
// (because we can't know the WHERE is on the right table)
else if (boost::algorithm::ifind_first(query, "WHERE")
&& !boost::algorithm::ifind_first(query, "JOIN"))
{
std::string replace(" WHERE " + spatial_sql.str() + " AND ");
boost::algorithm::ireplace_first(query, "WHERE", replace);
return true;
}
// fallback to appending spatial filter at end of query
else if (boost::algorithm::ifind_first(query, geometry_table))
{
query = table + " WHERE " + spatial_sql.str();
return true;
}
return false;
}
static void get_tables(boost::shared_ptr<sqlite_connection> ds,
std::vector<std::string> & tables)
{
@ -572,6 +608,7 @@ public:
// PRAGMA table_info is used so here we assume the column is a string
// which is a lesser evil than altogether dropping the column
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String));
break;
case SQLITE_BLOB:
if (geometry_field.empty()

View file

@ -1,7 +1,7 @@
<!DOCTYPE Map>
<Map background-color="white" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<MarkersSymbolizer stroke="green" stroke-width="1.3" fill="yellow"/>
<LineSymbolizer stroke-width=".2" stroke="grey"/>
</Rule>

View file

@ -2,31 +2,31 @@
<Map background-color="white" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([name]='CHILE')</Filter>
<MarkersSymbolizer fill="darkgreen" opacity=".7" width="15" height="10" stroke="green" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Australia')</Filter>
<MarkersSymbolizer fill="darkblue" opacity=".7" width="10" height="20" stroke="blue" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil')</Filter>
<MarkersSymbolizer fill="darkorange" opacity=".7" width="20" height="10" stroke="orange" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Mongolia')</Filter>
<MarkersSymbolizer fill="darkgoldenrod" opacity=".7" width="25" height="10" stroke="yellow" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Sudan')</Filter>
<MarkersSymbolizer fill="darkcyan" opacity=".7" width="15" height="10" stroke="cadetblue" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='United States')</Filter>
<MarkersSymbolizer fill="#cc3344" opacity=".7" width="15" height="10" stroke="#cc3344" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<PointSymbolizer file="../svg/ellipses.svg"/>
</Rule>

View file

@ -1,17 +1,17 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([x]=0)</Filter>
<TextSymbolizer size="10" dy="-10" face-name="DejaVu Sans Book" halo-radius="1" allow-overlap="true">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([y]=0)</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="-5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>

View file

@ -1,17 +1,17 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([x]=0)</Filter>
<TextSymbolizer size="10" dy="-10" face-name="DejaVu Sans Book" halo-radius="1" allow-overlap="true">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([y]=0)</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="-5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>

View file

@ -1,17 +1,17 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([x]=0)</Filter>
<TextSymbolizer size="10" dy="-10" face-name="DejaVu Sans Book" halo-radius="1" allow-overlap="true">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([y]=0)</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="-5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>

View file

@ -1,38 +1,38 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([name]='CHILE')</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" text-transform="lowercase" wrap-width="10" wrap-character=" " halo-radius="1">[name] + ' (default OGC pixel)'</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Australia')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (png)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.png" allow-overlap="true"/>
</Rule>
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (svg &amp; tif)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.tif" allow-overlap="true"/>
<PointSymbolizer file="../svg/ellipses.svg" allow-overlap="true"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Mongolia')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (tiff)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.tiff" allow-overlap="true"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Sudan')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (jpeg)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.jpeg"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='United States')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (jpg)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.jpg"/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name]</TextSymbolizer>
<PointSymbolizer file="../images/bogus_will_fail.png"/>

View file

@ -1,11 +1,11 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil' or [name]='Mongolia' or [name]='Sudan')</Filter>
<PointSymbolizer file="../svg/point_sm.svg" allow-overlap="true"/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<PointSymbolizer file="../svg/point_sm.svg" ignore-placement="true"/>
<PointSymbolizer/>

View file

@ -1,26 +1,26 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" minimum-version="0.7.2">
<Style name="test">
<Rule title="asia">
<Rule name="asia">
<Filter>([REGION]=142)</Filter>
<PointSymbolizer file="../images/dummy.png" allow-overlap="true"/>
</Rule>
<Rule title="europe">
<Rule name="europe">
<Filter>([REGION]=150)</Filter>
<!-- requires at least Mapnik 0.7.1 to work due to http://trac.mapnik.org/ticket/508 -->
<PolygonPatternSymbolizer file="../images/dummy.png"/>
</Rule>
<Rule title="americas">
<Rule name="americas">
<Filter>([REGION]=19)</Filter>
<!-- requires at least Mapnik 0.7.1 to work due to http://trac.mapnik.org/ticket/508 -->
<LinePatternSymbolizer file="../images/dummy.png"/>
</Rule>
<Rule title="Africa">
<Rule name="Africa">
<Filter>([REGION]=2)</Filter>
<ShieldSymbolizer placement="vertex" size="10" fill="#000000" file="../images/dummy.png" face-name="DejaVu Sans Bold">[NAME]</ShieldSymbolizer>
</Rule>
<Rule title="rest">
<Rule name="rest">
<ElseFilter/>
<LineSymbolizer stroke-width="1"/>
</Rule>

View file

@ -1,31 +1,31 @@
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" background-color="steelblue" minimum-version="0.7.2">
<Style name="labels">
<Rule title="foo">
<Rule>
<Filter>([name]='CHILE')</Filter>
<TextSymbolizer size="15" orientation="45" face-name="DejaVu Sans Book" halo-radius="1">'45˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Australia')</Filter>
<TextSymbolizer size="15" orientation="-45" face-name="DejaVu Sans Book" halo-radius="1">'- 45˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil')</Filter>
<TextSymbolizer size="15" orientation="90" face-name="DejaVu Sans Book" halo-radius="1">'90˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Mongolia')</Filter>
<TextSymbolizer size="15" orientation="-90" face-name="DejaVu Sans Book" halo-radius="1">'- 90˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='South Sudan')</Filter>
<TextSymbolizer size="15" orientation="180" face-name="DejaVu Sans Book" halo-radius="1">'180&#730; angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='United States')</Filter>
<TextSymbolizer size="15" face-name="DejaVu Sans Book" halo-radius="1">'no rotation of text'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="15" face-name="DejaVu Sans Book" halo-radius="1">[name]</TextSymbolizer>
</Rule>

View file

@ -213,12 +213,10 @@ def test_layer_init():
eq_(l.clear_label_cache,False)
eq_(l.cache_features,False)
eq_(l.visible(1),True)
eq_(l.abstract,'')
eq_(l.active,True)
eq_(l.datasource,None)
eq_(l.queryable,False)
eq_(l.srs,'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
eq_(l.title,'')
# Map initialization
def test_map_init():
@ -399,7 +397,6 @@ def test_rule_init():
r = mapnik.Rule()
eq_(r.name, '')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
@ -420,34 +417,30 @@ def test_rule_init():
r = mapnik.Rule("Name")
eq_(r.name, 'Name')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
eq_(r.has_also(), False)
r = mapnik.Rule("Name", "Title")
r = mapnik.Rule("Name")
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
eq_(r.has_also(), False)
r = mapnik.Rule("Name", "Title", min_scale)
r = mapnik.Rule("Name", min_scale)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, min_scale)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
eq_(r.has_also(), False)
r = mapnik.Rule("Name", "Title", min_scale, max_scale)
r = mapnik.Rule("Name", min_scale, max_scale)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, min_scale)
eq_(r.max_scale, max_scale)
eq_(r.has_else(), False)

View file

@ -15,7 +15,7 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
def test_attachdb_with_relative_file():
# The point table and index is in the qgis_spatiallite.sqlite
# database. If either is not found, then this fails
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='point',
attachdb='scratch@qgis_spatiallite.sqlite'
)
@ -24,7 +24,7 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature['pkuid'],1)
def test_attachdb_with_multiple_files():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='attachedtest',
attachdb='scratch1@:memory:,scratch2@:memory:',
initdb='''
@ -50,7 +50,7 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature['pkuid'],1)
def test_attachdb_with_index():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='attachedtest',
attachdb='scratch@:memory:',
initdb='''
@ -64,7 +64,7 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature,None)
def test_attachdb_with_explicit_index():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='attachedtest',
index_table='myindex',
attachdb='scratch@:memory:',
@ -79,10 +79,13 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature,None)
def test_attachdb_with_sql_join():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3 limit 100)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
fs = ds.featureset()
feature = fs.next()
eq_(feature.id(),1)
@ -125,9 +128,74 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
except:
#import pdb;pdb.set_trace()
print 'invalid key/v %s/%s for: %s' % (k,v,feature)
def test_attachdb_with_sql_join_count():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3 limit 100)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),100)
def test_attachdb_with_sql_join_count2():
'''
sqlite3 world.sqlite
attach database 'business.sqlite' as business;
select count(*) from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),192)
def test_attachdb_with_sql_join_count3():
'''
select count(*) from (select * from world_merc where 1=1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from (select * from world_merc where !intersects!) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),192)
def test_attachdb_with_sql_join_count4():
'''
select count(*) from (select * from world_merc where 1=1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from (select * from world_merc where !intersects! limit 1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),1)
def test_attachdb_with_sql_join_count5():
'''
select count(*) from (select * from world_merc where 1=1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from (select * from world_merc where !intersects! and 1=2) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
# nothing is able to join to business so we don't pick up business schema
eq_(len(ds.fields()),12)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float'])
eq_(len(ds.all_features()),0)
def test_subqueries():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='world_merc',
)
fs = ds.featureset()
@ -145,7 +213,7 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature['lon'],-61.783)
eq_(feature['lat'],17.078)
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from world_merc)',
)
fs = ds.featureset()
@ -163,7 +231,7 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature['lon'],-61.783)
eq_(feature['lat'],17.078)
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select OGC_FID,GEOMETRY from world_merc)',
)
fs = ds.featureset()
@ -171,24 +239,26 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature['OGC_FID'],1)
eq_(len(feature),1)
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select GEOMETRY,OGC_FID,fips from world_merc)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature['OGC_FID'],1)
eq_(feature['fips'],u'AC')
# same as above, except with alias like postgres requires
# TODO - should we try to make this work?
#ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
# table='(select GEOMETRY,rowid as aliased_id,fips from world_merc) as table',
# key_field='aliased_id'
# )
#fs = ds.featureset()
#feature = fs.next()
#eq_(feature['aliased_id'],1)
#eq_(feature['fips'],u'AC')
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select GEOMETRY,rowid as aliased_id,fips from world_merc)',
key_field='aliased_id'
)
fs = ds.featureset()
feature = fs.next()
eq_(feature['aliased_id'],1)
eq_(feature['fips'],u'AC')
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select GEOMETRY,OGC_FID,OGC_FID as rowid,fips from world_merc)',
)
fs = ds.featureset()
@ -220,6 +290,31 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
query.add_property_name('bogus')
fs = ds.features(query)
def test_intersects_token1():
ds = mapnik.SQLite(file='../data/sqlite/empty.db',
table='(select * from empty where !intersects!)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
def test_intersects_token1():
ds = mapnik.SQLite(file='../data/sqlite/empty.db',
table='(select * from empty where "a"!="b" and !intersects!)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
def test_intersects_token1():
ds = mapnik.SQLite(file='../data/sqlite/empty.db',
table='(select * from empty where "a"!="b" and !intersects!)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]

View file

@ -28,20 +28,6 @@ CONFIG_FONTS='%(fonts)s'
CONFIG_INPUT_PLUGINS='%(input_plugins)s'
CONFIG_GIT_REVISION='%(git_revision)s'
CONFIG_JSON="{
\\"prefix\\": \\"${CONFIG_PREFIX}\\",
\\"mapnik_libname\\": \\"${CONFIG_MAPNIK_LIBNAME}\\",
\\"mapnik_include\\": \\"${CONFIG_MAPNIK_INCLUDE}\\",
\\"mapnik_lib\\": \\"${CONFIG_MAPNIK_LIB}\\",
\\"version\\": \\"${CONFIG_MAPNIK_VERSION}\\",
\\"ldflags\\": \\"${CONFIG_MAPNIK_LDFLAGS}\\",
\\"dep_libs\\": \\"${CONFIG_DEP_LIBS}\\",
\\"other_includes\\": \\"${CONFIG_OTHER_INCLUDES}\\",
\\"fonts\\": \\"${CONFIG_FONTS}\\",
\\"input_plugins\\": \\"${CONFIG_INPUT_PLUGINS}\\",
\\"git_revision\\": \\"${CONFIG_GIT_REVISION}\\",
}"
'''
def write_config(configuration,template,config_file):

View file

@ -1,6 +1,20 @@
## program below
CONFIG_JSON="{
\"prefix\": \"${CONFIG_PREFIX}\",
\"mapnik_libname\": \"${CONFIG_MAPNIK_LIBNAME}\",
\"mapnik_include\": \"${CONFIG_MAPNIK_INCLUDE}\",
\"mapnik_lib\": \"${CONFIG_MAPNIK_LIB}\",
\"version\": \"${CONFIG_MAPNIK_VERSION}\",
\"ldflags\": \"${CONFIG_MAPNIK_LDFLAGS}\",
\"dep_libs\": \"${CONFIG_DEP_LIBS}\",
\"other_includes\": \"${CONFIG_OTHER_INCLUDES}\",
\"fonts\": \"${CONFIG_FONTS}\",
\"input_plugins\": \"${CONFIG_INPUT_PLUGINS}\",
\"git_revision\": \"${CONFIG_GIT_REVISION}\"
}"
usage()
{
cat <<EOF

View file

@ -69,7 +69,6 @@
<!ELEMENT Layer (StyleName|Datasource)*>
<!-- FIXME: queryable true/false ? -->
<!ATTLIST Layer
abstract CDATA #IMPLIED
clear_label_cache (yes|1|no|0) #IMPLIED
minzoom CDATA "0"
maxzoom CDATA #IMPLIED
@ -77,7 +76,6 @@
queryable (true|on|1|false|off|0) "0"
srs CDATA #IMPLIED
status (on|1|off|0) "1"
title CDATA ""
tolerance CDATA #IMPLIED
toleranceunits CDATA #IMPLIED
>
@ -90,7 +88,6 @@
<!-- FIXME: MapnikXMLDescription.pdf specified name is required? -->
<!ATTLIST Rule
name CDATA #IMPLIED
title CDATA #IMPLIED
>
<!ELEMENT Filter (#PCDATA)>