2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2008-11-16 23:30:44 +01:00
|
|
|
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon, Dane Springmeyer
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2006-02-01 00:09:52 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2006-02-01 00:09:52 +01:00
|
|
|
//$Id: mapnik_layer.cc 17 2005-03-08 23:58:43Z pavlenko $
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <boost/python/detail/api_placeholder.hpp>
|
|
|
|
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/layer.hpp>
|
2006-02-01 00:09:52 +01:00
|
|
|
|
|
|
|
using mapnik::Layer;
|
|
|
|
using mapnik::parameters;
|
|
|
|
|
2006-12-20 01:22:45 +01:00
|
|
|
std::vector<std::string> & (mapnik::Layer::*_styles_)() = &mapnik::Layer::styles;
|
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_layer()
|
|
|
|
{
|
|
|
|
using namespace boost::python;
|
2007-11-08 12:06:05 +01:00
|
|
|
class_<std::vector<std::string> >("Names")
|
2006-02-01 00:09:52 +01:00
|
|
|
.def(vector_indexing_suite<std::vector<std::string>,true >())
|
|
|
|
;
|
2006-02-25 12:03:30 +01:00
|
|
|
|
2008-11-16 23:30:44 +01:00
|
|
|
class_<Layer>("Layer", "A Mapnik map layer.", init<std::string const&,optional<std::string const&> >(
|
|
|
|
"Create a Layer with a named string and, optionally, an srs string either with\n"
|
|
|
|
"a Proj.4 epsg code ('+init=epsg:<code>') or with a Proj.4 literal ('+proj=<literal>').\n"
|
|
|
|
"If no srs is specified it will default to '+proj=latlong +datum=WGS84'\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
|
|
|
">>> lyr\n"
|
|
|
|
"<mapnik._mapnik.Layer object at 0x6a270>"
|
|
|
|
))
|
|
|
|
|
|
|
|
.def("envelope",&Layer::envelope,
|
|
|
|
"Return the geographic envelope/bounding box "
|
|
|
|
"of the data in the layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.envelope()\n"
|
|
|
|
"Envelope(-1.0,-1.0,0.0,0.0) # default until a datasource is loaded\n"
|
|
|
|
)
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2008-11-16 23:30:44 +01:00
|
|
|
.def("visible", &Layer::isVisible,
|
|
|
|
"Return True if this layer's data is active and visible at a given scale.\n"
|
|
|
|
"Otherwise returns False.\n"
|
|
|
|
"Accepts a scale value as an integer or float input.\n"
|
|
|
|
"Will return False if:\n"
|
|
|
|
"\tscale >= minzoom - 1e-6\n"
|
|
|
|
"\tor:\n"
|
|
|
|
"\tscale < maxzoom + 1e-6\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.visible(1.0/1000000)\n"
|
|
|
|
"True\n"
|
|
|
|
">>> lyr.active = False\n"
|
|
|
|
">>> lyr.visible(1.0/1000000)\n"
|
|
|
|
"False\n"
|
|
|
|
)
|
|
|
|
|
2006-10-03 10:44:04 +02:00
|
|
|
.add_property("abstract",
|
2008-11-16 23:30:44 +01:00
|
|
|
make_function(&Layer::abstract,return_value_policy<copy_const_reference>()),
|
|
|
|
&Layer::set_abstract,
|
|
|
|
"Get/Set the abstract of the layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.abstract\n"
|
|
|
|
"'' # default is en empty string\n"
|
|
|
|
">>> lyr.abstract = 'My Shapefile rendered with Mapnik'\n"
|
|
|
|
">>> lyr.abstract\n"
|
|
|
|
"'My Shapefile rendered with Mapnik'\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_property("active",
|
|
|
|
&Layer::isActive,
|
|
|
|
&Layer::setActive,
|
|
|
|
"Get/Set whether this layer is active and will be rendered.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.active\n"
|
|
|
|
"True # Active by default\n"
|
|
|
|
">>> lyr.active = False # set False to disable layer rendering\n"
|
|
|
|
">>> lyr.active\n"
|
|
|
|
"False\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_property("clear_label_cache",
|
|
|
|
&Layer::clear_label_cache,
|
|
|
|
&Layer::set_clear_label_cache,
|
|
|
|
"Get/Set whether this layer's labels are cached."
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
|
|
|
"TODO"
|
|
|
|
)
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2008-11-16 23:30:44 +01:00
|
|
|
.add_property("datasource",
|
|
|
|
&Layer::datasource,
|
|
|
|
&Layer::set_datasource,
|
|
|
|
"The datasource attached to this layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer, Datasource\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.datasource = Datasource(type='shape',file='world_borders')\n"
|
|
|
|
">>> lyr.datasource\n"
|
|
|
|
"<mapnik.Datasource object at 0x65470>\n"
|
|
|
|
)
|
|
|
|
|
2006-10-03 10:44:04 +02:00
|
|
|
.add_property("maxzoom",
|
2008-11-16 23:30:44 +01:00
|
|
|
&Layer::getMaxZoom,
|
|
|
|
&Layer::setMaxZoom,
|
|
|
|
"Get/Set the maximum zoom lever of the layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.maxzoom\n"
|
|
|
|
"1.7976931348623157e+308 # default is the numerical maximum\n"
|
|
|
|
">>> lyr.maxzoom = 1.0/1000000\n"
|
|
|
|
">>> lyr.maxzoom\n"
|
|
|
|
"9.9999999999999995e-07\n"
|
|
|
|
)
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2008-11-16 23:30:44 +01:00
|
|
|
.add_property("minzoom",
|
|
|
|
&Layer::getMinZoom,
|
|
|
|
&Layer::setMinZoom,
|
|
|
|
"Get/Set the minimum zoom lever of the layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.minzoom # default is 0\n"
|
|
|
|
"0.0\n"
|
|
|
|
">>> lyr.minzoom = 1.0/1000000\n"
|
|
|
|
">>> lyr.minzoom\n"
|
|
|
|
"9.9999999999999995e-07\n"
|
|
|
|
)
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2008-11-16 23:30:44 +01:00
|
|
|
.add_property("name",
|
|
|
|
make_function(&Layer::name, return_value_policy<copy_const_reference>()),
|
|
|
|
&Layer::set_name,
|
|
|
|
"Get/Set the name of the layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.name\n"
|
|
|
|
"'My Layer'\n"
|
|
|
|
">>> lyr.name = 'New Name'\n"
|
|
|
|
">>> lyr.name\n"
|
|
|
|
"'New Name'\n"
|
|
|
|
)
|
2006-12-17 13:08:11 +01:00
|
|
|
|
2007-01-09 12:23:19 +01:00
|
|
|
.add_property("queryable",
|
2008-11-16 23:30:44 +01:00
|
|
|
&Layer::isQueryable,
|
|
|
|
&Layer::setQueryable,
|
|
|
|
"Get/Set whether this layer is queryable.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.queryable\n"
|
|
|
|
"False # Not queryable by default\n"
|
|
|
|
">>> lyr.queryable = True\n"
|
|
|
|
">>> lyr.queryable\n"
|
|
|
|
"True\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_property("srs",
|
|
|
|
make_function(&Layer::srs,return_value_policy<copy_const_reference>()),
|
|
|
|
&Layer::set_srs,
|
|
|
|
"Get/Set the SRS of the layer."
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.srs\n"
|
|
|
|
"'+proj=latlong +datum=WGS84' # The default srs if not initialized with custom srs\n"
|
|
|
|
">>> # set to google mercator with Proj.4 literal\n"
|
|
|
|
"... \n"
|
|
|
|
">>> lyr.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 +no_defs +over'\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_property("styles",
|
|
|
|
make_function(_styles_,return_value_policy<reference_existing_object>()),
|
|
|
|
"The styles list attached to this layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.styles\n"
|
|
|
|
"<mapnik._mapnik.Names object at 0x6d3e8>\n"
|
|
|
|
">>> len(lyr.styles)\n"
|
|
|
|
"0\n # no styles until you append them"
|
|
|
|
"lyr.styles.append('My Style') # mapnik uses named styles for flexibility\n"
|
|
|
|
">>> len(lyr.styles)\n"
|
|
|
|
"1\n"
|
|
|
|
">>> lyr.styles[0]\n"
|
|
|
|
"'My Style'\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_property("title",
|
|
|
|
make_function(&Layer::title, return_value_policy<copy_const_reference>()),
|
|
|
|
&Layer::set_title,
|
|
|
|
"Get/Set the title of the layer.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage:\n"
|
2008-12-05 00:33:18 +01:00
|
|
|
">>> from mapnik import Layer\n"
|
|
|
|
">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n"
|
2008-11-16 23:30:44 +01:00
|
|
|
">>> lyr.title\n"
|
|
|
|
"''\n"
|
|
|
|
">>> lyr.title = 'My first layer'\n"
|
|
|
|
">>> lyr.title\n"
|
|
|
|
"'My first layer'\n"
|
|
|
|
)
|
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
;
|
|
|
|
}
|