1,5 → 1,5 |
// |
// C++ Implementation: render |
// C++ Implementation: SRender |
// |
// Description: Renders a map from some shape files. This class assumes, |
// that the shape files are in open street map format! |
12,17 → 12,21 |
// |
|
#define BOOST_SPIRIT_THREADSAFE |
#include <mapnik/map.hpp> |
#include <mapnik/datasource_cache.hpp> |
#include <mapnik/font_engine_freetype.hpp> |
#include <mapnik/agg_renderer.hpp> |
#include <mapnik/filter_factory.hpp> |
#include <mapnik/color_factory.hpp> |
#include <mapnik/image_util.hpp> |
#include <mapnik/config_error.hpp> |
#include <QLabel> |
#include <QString> |
#include <QXmlReader> |
#include <QDir> |
#include <QColor> |
#include <KStandardDirs> |
#include <KConfig> |
#include <KLocale> |
#include <KMessageBox> |
#include <KGlobalSettings> |
#include <KConfigGroup> |
|
#include "config.h" |
#include "render.h" |
#include <iostream> |
|
#define CON_MAP 100 |
#define CON_STYLE 101 |
34,6 → 38,8 |
#define CON_POLYGONPATTERNSYMBOLIZER 107 |
#define CON_LAYER 108 |
#define CON_DATASOURCE 109 |
#define CON_SHIELDSYMBOLIZER 110 |
#define CON_LINEPATTERNSYMBOLIZER 111 |
|
#define FLD_FILTER 200 |
#define FLD_CSSPARAMETER 201 |
61,7 → 67,7 |
#define ATT_SRS 316 |
|
#define FIRST_CON 100 |
#define LAST_CON 109 |
#define LAST_CON 111 |
|
#define FIRST_FLD 200 |
#define LAST_FLD 205 |
69,50 → 75,59 |
#define FIRST_ATT 300 |
#define LAST_ATT 316 |
|
KEYS keys[] = { |
using std::cout; |
using std::cerr; |
using std::clog; |
using std::endl; |
|
TOKEN token[] = { |
// Containers |
{ CON_MAP QString("Map") }, |
{ CON_STYLE QString("Style") }, |
{ CON_RULE QString("Rule") }, |
{ CON_LINESYMBOLIZER QString("LineSymbolizer") }, |
{ CON_POINTSYMBOLIZER QString("PointSymbolizer") }, |
{ CON_POLYGONSYMBOLIZER QString("PolygonSymbolizer") }, |
{ CON_TEXTSYMBOLIZER QString("TextSymbolizer") }, |
{ CON_POLYGONPATTERNSYMBOLIZER QString("PolygonPatternSymbolizer") }, |
{ CON_LAYER QString("Layer") }, |
{ CON_DATASOURCE QString("Datasource") }, |
{ CON_MAP, in_map, QString("Map") }, |
{ CON_STYLE, in_style, QString("Style") }, |
{ CON_RULE, in_rule, QString("Rule") }, |
{ CON_LINESYMBOLIZER, in_linesymbolizer, QString("LineSymbolizer") }, |
{ CON_POINTSYMBOLIZER, in_pointsymbolizer, QString("PointSymbolizer") }, |
{ CON_POLYGONSYMBOLIZER, in_polygonsymbolizer, QString("PolygonSymbolizer") }, |
{ CON_TEXTSYMBOLIZER, in_textsymbolizer, QString("TextSymbolizer") }, |
{ CON_POLYGONPATTERNSYMBOLIZER, in_polygonpatternsymbolizer, QString("PolygonPatternSymbolizer") }, |
{ CON_LAYER, in_layer, QString("Layer") }, |
{ CON_DATASOURCE, in_datasource, QString("Datasource") }, |
{ CON_SHIELDSYMBOLIZER, in_shieldsymbolizer, QString("ShieldSymbolizer") }, |
// Fields |
{ FLD_FILTER QString("Filter") }, |
{ FLD_CSSPARAMETER QString("CSSParameter") }, |
{ FLD_MINSCALE QString("MinScaleDenominator") }, |
{ FLD_MAXSCALE QString("MaxScaleDenominator") }, |
{ FLD_STYLENAME QString("StyleName") }, |
{ FLD_PARAMETER QString("Parameter") }, |
{ FLD_FILTER, in_rule, QString("Filter") }, |
{ FLD_CSSPARAMETER, in_symbolizer, QString("CSSParameter") }, |
{ FLD_MINSCALE, in_rule, QString("MinScaleDenominator") }, |
{ FLD_MAXSCALE, in_rule, QString("MaxScaleDenominator") }, |
{ FLD_STYLENAME, in_style, QString("StyleName") }, |
{ FLD_PARAMETER, in_datasource, QString("Parameter") }, |
// Attributes |
{ ATT_FILL QString("fill") }, |
{ ATT_NAME QString("name") }, |
{ ATT_FILE QString("file") }, |
{ ATT_TYPE QString("type") }, |
{ ATT_WIDTH QString("width") }, |
{ ATT_HEIGHT QString("height") }, |
{ ATT_SIZE QString("size") }, |
{ ATT_FACENAME QString("face_name") }, |
{ ATT_DY QString("dy") }, |
{ ATT_HALORADIUS QString("halo_radius") }, |
{ ATT_WRAPWIDTH QString("wrap_width") }, |
{ ATT_MINDISTANCE QString("min_distance") }, |
{ ATT_MAXDISTANCE QString("max_distance") }, |
{ ATT_PLACEMAENT QString("placement") }, |
{ ATT_ALLOWOVERLAP QString("allow_overlap") }, |
{ ATT_STATUS QString("status") }, |
{ ATT_SRS QString("srs") }, |
{ 0 QString::null } |
{ ATT_FILL, in_symbolizer, QString("fill") }, |
{ ATT_NAME, in_symbolizer, QString("name") }, |
{ ATT_FILE, in_symbolizer, QString("file") }, |
{ ATT_TYPE, in_symbolizer, QString("type") }, |
{ ATT_WIDTH, in_symbolizer, QString("width") }, |
{ ATT_HEIGHT, in_symbolizer, QString("height") }, |
{ ATT_SIZE, in_symbolizer, QString("size") }, |
{ ATT_FACENAME, in_symbolizer, QString("face_name") }, |
{ ATT_DY, in_symbolizer, QString("dy") }, |
{ ATT_HALORADIUS, in_symbolizer, QString("halo_radius") }, |
{ ATT_WRAPWIDTH, in_symbolizer, QString("wrap_width") }, |
{ ATT_MINDISTANCE, in_symbolizer, QString("min_distance") }, |
{ ATT_MAXDISTANCE, in_symbolizer, QString("max_distance") }, |
{ ATT_PLACEMENT, in_symbolizer, QString("placement") }, |
{ ATT_ALLOWOVERLAP, in_symbolizer, QString("allow_overlap") }, |
{ ATT_STATUS, in_layer, QString("status") }, |
{ ATT_SRS, in_layer, QString("srs") }, |
{ 0, in_root, QString::null } |
}; |
|
render::render() |
SRender::SRender() |
{ |
Layer = 0; |
Style = 0; |
label = 0; |
shapePath = QString::null; |
XmlPath = QString::null; |
Lay = firstLayer = lastLayer = 0; |
Style = firstStyle = lastStyle = 0; |
Rule = 0; |
LineSymbolizer = 0; |
PolygonSymbolizer = 0; |
121,12 → 136,57 |
PolygonPatternSymbolizer = 0; |
ShieldSymbolizer = 0; |
LinePatternSymbolizer = 0; |
// This is true, when a XML file was parsed successfully |
ControlSet = false; |
|
// Read settings from config file |
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig); |
KConfigGroup ic (&cfg, "SportWatcher"); |
KConfigGroup sh (&cfg, "ShapeFile"); |
QString basePath = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher"); |
shapePath = ic.readEntry("MAP", basePath + "/shapefiles"); |
// Read the shape specific informations |
#ifdef MAPNIK_PLUGINS |
pluginPath = QString(MAPNIK_PLUGINS); |
#else |
// Test some default path |
if (dir.exists(QString("/usr/lib/mapnik/input"))) |
pluginPath = sh.readEntry("PluginPath", QString("/usr/lib/mapnik/input")); |
else if (dir.exists(QString("/usr/local/lib/mapnik/input"))) |
pluginPath = sh.readEntry("PluginPath", QString("/usr/local/lib/mapnik/input")); |
else if (dir.exists(QString("/usr/lib/mapnik/0.6/input"))) |
pluginPath = sh.readEntry("PluginPath", QString("/usr/lib/mapnik/0.6/input")); |
else |
pluginPath = sh.readEntry("PluginPath", QString("")); |
#endif |
#ifdef MAPNIK_FONTS |
fontPath = QString(MAPNIK_FONTS); |
#else |
// Test some default path |
if (dir.exists(QString("/usr/lib/mapnik/fonts"))) |
fontPath = sh.readEntry("FontPath", QString("/usr/lib/mapnik/fonts")); |
else if (dir.exists(QString("/usr/local/lib/mapnik/fonts"))) |
fontPath = sh.readEntry("FontPath", QString("/usr/local/lib/mapnik/fonts")); |
else if (dir.exists(QString("/usr/share/mapnik/fonts"))) |
fontPath = sh.readEntry("FontPath", QString("/usr/share/mapnik/fonts")); |
else if (dir.exists(QString("/usr/share/fonts/truetype/ttf-dejavu"))) |
fontPath = sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu")); |
else |
fontPath = sh.readEntry("FontPath", QString("")); |
#endif |
XmlPath = sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml"); |
} |
|
bool render::startDocument() |
SRender::~SRender() |
{ |
indent = 0; |
startDocument(); // Clean everything |
ControlSet = false; |
} |
|
bool SRender::startDocument() |
{ |
m.remove_all(); // delete styles and layers from map |
|
if (firstStyle) // free if allocated |
{ |
Style = firstStyle; |
133,10 → 193,11 |
|
while (Style) |
{ |
STYLE *sakt = Style->next; |
|
if (Style->rule) |
{ |
RULE *rule = Style->rule; |
STYLE *sakt = Style->next; |
|
while (rule) |
{ |
146,7 → 207,7 |
TEXTSYMBOLIZER *TextSymbolizer = rule->TextSymbolizer; |
POINTSYMBOLIZER *PointSymbolizer = rule->PointSymbolizer; |
POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer = rule->PolygonPatternSymbolizer; |
SHIELDSYMBOLIZER *ShieldSymbolizer = rule->ShielSymbolizer; |
SHIELDSYMBOLIZER *ShieldSymbolizer = rule->ShieldSymbolizer; |
LINEPATTERNSYMBOLIZER *LinePatternSymbolizer = rule->LinePatternSymbolizer; |
|
while (LineSymbolizer) |
209,6 → 270,23 |
} |
|
Style = firstStyle = lastStyle = 0; |
|
if (firstLayer) |
{ |
Lay = firstLayer; |
|
while (Lay) |
{ |
LAYER *akt; |
|
akt = Lay->next; |
delete Lay; |
Lay = akt; |
} |
} |
|
Lay = firstLayer = lastLayer = 0; |
Container = in_root; |
return true; |
} |
|
215,24 → 293,33 |
/* |
* This is called every time a new start element was parsed. |
*/ |
bool render::startElement( const QString&, const QString&, |
bool SRender::startElement( const QString&, const QString&, |
const QString& qName, |
const QXmlAttributes& att) |
{ |
int i = FIRST_CON; |
int index; |
QString hv0; |
|
indent++; |
|
while (i < LAST_CON) |
while (i <= LAST_CON) |
{ |
if (qName.toLower() == getKey(i).toLower()) |
{ |
Container = token[i].con; |
|
switch (i) |
{ |
case CON_MAP: |
Container = in_map; |
|
if (ControlSet) // Must be false here! |
{ |
KMessageBox::error(0, i18n("Error parsing %1: There is another MAP! Only one map information is allowed!").arg(XmlPath)); |
return false; |
} |
|
if ((index = att.index(QString("bgcolor"))) != -1) |
MapPars.bgcolor = color_factory::from_string(att.value(index).toAscii().data()); |
MapPars.bgcolor = colorToUInt(att.value(index)); |
|
if ((index = att.index(QString("buffer_size"))) != -1) |
MapPars.buf_size = att.value(index).toInt(); |
239,19 → 326,20 |
|
if ((index = att.index(QString("srs"))) != -1) |
MapPars.srs = att.value(index); |
cout << "<Map bgcolor=" << MapPars.bgcolor << " buffer_size=" << MapPars.buf_size << " srs=" << MapPars.srs.toAscii().data() << ">" << endl; |
break; |
|
case CON_STYLE: |
Container = in_style; |
|
if (!lastStyle) |
{ |
Style = new STYLE; |
fistStyle = lastStyle = Style; |
memset (Style, 0, sizeof (STYLE)); |
Style = allocStyle(); |
firstStyle = lastStyle = Style; |
} |
else |
{ |
Style = new STYLE; |
memset (Style, 0, sizeof (STYLE)); |
Style = allocStyle(); |
lastStyle->next = Style; |
lastStyle = Style; |
} |
260,12 → 348,15 |
Style->name = att.value(index); |
else |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open STYLE wihout a name!").arg(XmlPath)); |
KMessageBox::error(0, i18n("Error parsing %1: Open STYLE without a name!").arg(XmlPath)); |
return false; |
} |
cout << " <Style name=" << Style->name.toAscii().data() << ">" << endl; |
break; |
|
case CON_RULE: |
Container = in_rule; |
|
if (!Style) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open RULE outside of a STYLE!").arg(XmlPath)); |
276,19 → 367,50 |
|
if (!Rule) |
{ |
Rule = new RULE; |
memset (Rule, 0, sizeof(RULE)); |
Rule = allocRule(); |
Style->rule = Rule; |
} |
else |
{ |
Rule->next = new RULE; |
Rule->next = allocRule(); |
Rule = Rule->next; |
memset (Rule, 0, sizeof(RULE)); |
} |
cout << " <Rule>" << endl; |
break; |
|
case CON_LAYER: |
Container = in_layer; |
|
if (!firstLayer) |
{ |
Lay = allocLayer(); |
firstLayer = lastLayer = Lay; |
} |
else |
{ |
Lay = allocLayer(); |
lastLayer->next = Lay; |
lastLayer = Lay; |
} |
|
if ((index = att.index(QString("name"))) != -1) |
Lay->name = att.value(index); |
|
if ((index = att.index(QString("status"))) != -1) |
Lay->status = getBool(att.value(index)); |
|
if ((index = att.index(QString("srs"))) != -1) |
Lay->srs = att.value(index); |
cout << " <Layer name=" << Lay->name.toAscii().data() << " status=" << Lay->status << " srs=" << Lay->srs.toAscii().data() << ">" << endl; |
break; |
|
case CON_DATASOURCE: |
Container = in_datasource; |
break; |
|
case CON_POINTSYMBOLIZER: |
Container = in_pointsymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open POINTSYMBOLIZER outside of a RULE!").arg(XmlPath)); |
299,15 → 421,13 |
|
if (!PointSymbolizer) |
{ |
PointSymbolizer = new POINTSYMBOLIZER; |
memset (PointSymbolizer, 0, sizeof(POINTSYMBOLIZER)); |
PointSymbolizer = allocPointSymbolizer(); |
Rule->PointSymbolizer = PointSymbolizer; |
} |
else |
{ |
PointSymbolizer->next = new POINTSYMBOLIZER; |
PointSymbolizer->next = allocPointSymbolizer(); |
PointSymbolizer = PointSymbolizer->next; |
memset (PointSymbolizer, 0, sizeof(POINTSYMBOLIZER)); |
} |
|
if ((index = att.index(QString("file"))) != -1) |
314,30 → 434,15 |
PointSymbolizer->file = att.value(index); |
|
if ((index = att.index(QString("type"))) != -1) |
{ |
QString ty = att.value(index); |
PointSymbolizer->type = getType(att.value(index)); |
|
if (ty.toLower() == QString("png")) |
PointSymbolizer->type = type_png; |
else if (ty.toLower() == QString("gif")) |
PointSymbolizer->type = type_gif; |
else if (ty.toLower() == QString("jpg")) |
PointSymbolizer->type = type_jpg; |
else if (ty.toLower() == QString("xpm")) |
PointSymbolizer->type = type_xpm; |
else if (ty.toLower() == QString("bmp")) |
PointSymbolizer->type = type_xmp; |
else if (ty.toLower() == QString("tif") || ty.toLower() == QString("tiff")) |
PointSymbolizer->type = type_tif; |
} |
|
if ((index = add.index(QString("width"))) != -1) |
if ((index = att.index(QString("width"))) != -1) |
PointSymbolizer->width = att.value(index).toDouble(); |
|
if ((index = add.index(QString("height"))) != -1) |
if ((index = att.index(QString("height"))) != -1) |
PointSymbolizer->height = att.value(index).toDouble(); |
|
if ((index = add.index(QString("allow_overlap"))) != -1) |
if ((index = att.index(QString("allow_overlap"))) != -1) |
{ |
if (att.value(index).toLower() == QString("true")) |
PointSymbolizer->allow_overlap = true; |
344,11 → 449,14 |
else |
PointSymbolizer->allow_overlap = false; |
} |
cout << " <Pointsymbolizer file=" << PointSymbolizer->file.toAscii().data() << " ... >" << endl; |
break; |
|
break; |
|
case CON_LINESYMBOLIZER: |
Container = in_linesymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open LINESYMBOLIZER outside of a RULE!").arg(XmlPath)); |
359,19 → 467,20 |
|
if (!LineSymbolizer) |
{ |
LineSymbolizer = new LINESYMBOLIZER; |
memset (LineSymbolizer, 0, sizeof(LINESYMBOLIZER)); |
LineSymbolizer = allocLineSymbolizer(); |
Rule->LineSymbolizer = LineSymbolizer; |
} |
else |
{ |
LineSymbolizer->next = new LINESYMBOLIZER; |
LineSymbolizer->next = allocLineSymbolizer(); |
LineSymbolizer = LineSymbolizer->next; |
memset (LineSymbolizer, 0, sizeof(LINESYMBOLIZER)); |
} |
cout << " <Linesymbolizer>" << endl; |
break; |
|
case CON_POLYGONSYMBOLIZER: |
Container = in_polygonsymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open POLYGONSYMBOLIZER outside of a RULE!").arg(XmlPath)); |
382,19 → 491,20 |
|
if (!PolygonSymbolizer) |
{ |
PolygonSymbolizer = new POLYGONSYMBOLIZER; |
memset (PolygonSymbolizer, 0, sizeof(POLYGONSYMBOLIZER)); |
PolygonSymbolizer = allocPolygonSymbolizer(); |
Rule->PolygonSymbolizer = PolygonSymbolizer; |
} |
else |
{ |
PolygonSymbolizer->next = new POLYGONSYMBOLIZER; |
PolygonSymbolizer->next = allocPolygonSymbolizer(); |
PolygonSymbolizer = PolygonSymbolizer->next; |
memset (PolygonSymbolizer, 0, sizeof(POLYGONSYMBOLIZER)); |
} |
cout << " <Polygonsymbolizer>" << endl; |
break; |
|
case CON_TEXTSYMBOLIZER: |
Container = in_textsymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open TEXTSYMBOLIZER outside of a RULE!").arg(XmlPath)); |
405,15 → 515,13 |
|
if (!TextSymbolizer) |
{ |
TextSymbolizer = new TEXTSYMBOLIZER; |
memset (TextSymbolizer, 0, sizeof(TEXTSYMBOLIZER)); |
TextSymbolizer = allocTextSymbolizer(); |
Rule->TextSymbolizer = TextSymbolizer; |
} |
else |
{ |
TextSymbolizer->next = new TEXTSYMBOLIZER; |
TextSymbolizer->next = allocTextSymbolizer(); |
TextSymbolizer = TextSymbolizer->next; |
memset (TextSymbolizer, 0, sizeof(TEXTSYMBOLIZER)); |
} |
|
if ((index = att.index(QString("name"))) != -1) |
426,16 → 534,534 |
TextSymbolizer->size = att.value(index).toDouble(); |
|
if ((index = att.index(QString("fill"))) != -1) |
TextSymbolizer->fill = |
TextSymbolizer->fill = colorToUInt(att.value(index)); |
|
if ((index = att.index(QString("halo_radius"))) != -1) |
TextSymbolizer->halo_radius = att.value(index).toDouble(); |
|
if ((index = att.index(QString("wrap_width"))) != -1) |
TextSymbolizer->wrap_width = att.value(index).toDouble(); |
|
if ((index = att.index(QString("dy"))) != -1) |
TextSymbolizer->dy = att.value(index).toDouble(); |
|
if ((index = att.index(QString("max_distance"))) != -1) |
TextSymbolizer->maxdistance = att.value(index).toDouble(); |
|
if ((index = att.index(QString("min_distance"))) != -1) |
TextSymbolizer->mindistance = att.value(index).toDouble(); |
cout << " <Textsymbolizer name=" << TextSymbolizer->name.toAscii().data() << " ... >" << endl; |
break; |
|
case CON_POLYGONPATTERNSYMBOLIZER: |
Container = in_polygonpatternsymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open POLYGONPATTERNSYMBOLIZER outside of a RULE!").arg(XmlPath)); |
return false; |
} |
|
PolygonPatternSymbolizer = getLastPolygonPatternSymbolizer(Rule->PolygonPatternSymbolizer); |
|
if (!PolygonPatternSymbolizer) |
{ |
PolygonPatternSymbolizer = allocPolygonPatternSymbolizer(); |
Rule->PolygonPatternSymbolizer = PolygonPatternSymbolizer; |
} |
else |
{ |
PolygonPatternSymbolizer->next = allocPolygonPatternSymbolizer(); |
PolygonPatternSymbolizer = PolygonPatternSymbolizer->next; |
} |
|
if ((index = att.index(QString("file"))) != -1) |
PolygonPatternSymbolizer->file = att.value(index); |
|
if ((index = att.index(QString("type"))) != -1) |
PolygonPatternSymbolizer->type = getType(att.value(index)); |
|
if ((index = att.index(QString("width"))) != -1) |
PolygonPatternSymbolizer->width = att.value(index).toDouble(); |
|
if ((index = att.index(QString("height"))) != -1) |
PolygonPatternSymbolizer->height = att.value(index).toDouble(); |
|
if ((index = att.index(QString("allow_overlap"))) != -1) |
PolygonPatternSymbolizer->allow_overlap = getBool(att.value(index)); |
cout << " <Polygonpatternsymbolizer file=" << PolygonPatternSymbolizer->file.toAscii().data() << " ... >" << endl; |
break; |
|
case CON_SHIELDSYMBOLIZER: |
Container = in_shieldsymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open SHIELDSYMBOLIZER outside of a RULE!").arg(XmlPath)); |
return false; |
} |
|
ShieldSymbolizer = getLastShieldSymbolizer(Rule->ShieldSymbolizer); |
|
if (!ShieldSymbolizer) |
{ |
ShieldSymbolizer = allocShieldSymbolizer(); |
Rule->ShieldSymbolizer = ShieldSymbolizer; |
} |
else |
{ |
ShieldSymbolizer->next = allocShieldSymbolizer(); |
ShieldSymbolizer = ShieldSymbolizer->next; |
} |
|
if ((index = att.index(QString("name"))) != -1) |
ShieldSymbolizer->name = att.value(index); |
|
if ((index = att.index(QString("face_name"))) != -1) |
ShieldSymbolizer->face_name = att.value(index); |
|
if ((index = att.index(QString("fill"))) != -1) |
ShieldSymbolizer->fill = colorToUInt(att.value(index)); |
|
if ((index = att.index(QString("placement"))) != -1) |
ShieldSymbolizer->placement = att.value(index); |
|
if ((index = att.index(QString("file"))) != -1) |
ShieldSymbolizer->file = att.value(index); |
|
if ((index = att.index(QString("type"))) != -1) |
ShieldSymbolizer->type = getType(att.value(index)); |
|
if ((index = att.index(QString("size"))) != -1) |
ShieldSymbolizer->size = att.value(index).toDouble(); |
|
if ((index = att.index(QString("width"))) != -1) |
ShieldSymbolizer->width = att.value(index).toDouble(); |
|
if ((index = att.index(QString("height"))) != -1) |
ShieldSymbolizer->height = att.value(index).toDouble(); |
|
if ((index = att.index(QString("min_distance"))) != -1) |
ShieldSymbolizer->mindistance = att.value(index).toDouble(); |
|
if ((index = att.index(QString("max_distance"))) != -1) |
ShieldSymbolizer->maxdistance = att.value(index).toDouble(); |
cout << " <Shieldsymbolizer name=" << ShieldSymbolizer->name.toAscii().data() << " ... >" << endl; |
break; |
|
case CON_LINEPATTERNSYMBOLIZER: |
Container = in_linepatternsymbolizer; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Open LINEPATTERNSYMBOLIZER outside of a RULE!").arg(XmlPath)); |
return false; |
} |
|
LinePatternSymbolizer = getLastLinePatternSymbolizer(Rule->LinePatternSymbolizer); |
|
if (!LinePatternSymbolizer) |
{ |
LinePatternSymbolizer = allocLinePatternSymbolizer(); |
Rule->LinePatternSymbolizer = LinePatternSymbolizer; |
} |
else |
{ |
LinePatternSymbolizer->next = allocLinePatternSymbolizer(); |
LinePatternSymbolizer = LinePatternSymbolizer->next; |
} |
|
if ((index = att.index(QString("file"))) != -1) |
LinePatternSymbolizer->file = att.value(index); |
|
if ((index = att.index(QString("type"))) != -1) |
LinePatternSymbolizer->type = getType(att.value(index)); |
|
if ((index = att.index(QString("width"))) != -1) |
LinePatternSymbolizer->width = att.value(index).toDouble(); |
|
if ((index = att.index(QString("height"))) != -1) |
LinePatternSymbolizer->height = att.value(index).toDouble(); |
cout << " <Linepatternsymbolizer file=" << LinePatternSymbolizer->file.toAscii().data() << " ... >" << endl; |
break; |
} |
} |
|
i++; |
} |
|
i = FIRST_FLD; |
|
while (i <= LAST_FLD) |
{ |
if (qName.toLower() == getKey(i).toLower()) |
{ |
Field = i; |
|
switch(Container) |
{ |
case in_linesymbolizer: |
Names = empty; |
|
if (i == FLD_CSSPARAMETER) |
{ |
if ((index = att.index(QString("name"))) != -1) |
{ |
if (att.value(index).toLower() == QString("stroke")) |
Names = stroke_stroke; |
else if (att.value(index).toLower() == QString("stroke-width")) |
Names = stroke_width; |
else if (att.value(index).toLower() == QString("stroke-opacity")) |
Names = stroke_opacity; |
else if (att.value(index).toLower() == QString("stroke-linejoin")) |
Names = stroke_linejoin; |
else if (att.value(index).toLower() == QString("stroke-linecap")) |
Names = stroke_linecap; |
else if (att.value(index).toLower() == QString("stroke-dasharray")) |
Names = stroke_dasharray; |
} |
else |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Required attribute NAME is missing in CSSPARAMETER inside LINESYMBOLIZER!").arg(XmlPath)); |
return false; |
} |
} |
break; |
|
case in_polygonsymbolizer: |
Names = empty; |
|
if (i == FLD_CSSPARAMETER) |
{ |
if ((index = att.index(QString("name"))) != -1) |
{ |
if (att.value(index).toLower() == QString("fill")) |
Names = fill; |
else if (att.value(index).toLower() == QString("fill-opacity")) |
Names = fill_opacity; |
} |
else |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Required attribute NAME is missing in CSSPARAMETER inside POLYGONSYMBOLIZER!").arg(XmlPath)); |
return false; |
} |
} |
break; |
|
case in_datasource: |
Names = empty; |
|
if (i == FLD_PARAMETER) |
{ |
if ((index = att.index(QString("name"))) != -1) |
{ |
if (att.value(index).toLower() == QString("type")) |
Names = type; |
else if (att.value(index).toLower() == QString("file")) |
Names = file; |
else if (att.value(index).toLower() == QString("host")) |
Names = host; |
else if (att.value(index).toLower() == QString("user")) |
Names = user; |
else if (att.value(index).toLower() == QString("dbname")) |
Names = dbname; |
else if (att.value(index).toLower() == QString("table")) |
Names = table; |
else if (att.value(index).toLower() == QString("estimate_extent")) |
Names = estimate_extent; |
else if (att.value(index).toLower() == QString("extent")) |
Names = extent; |
} |
else |
{ |
KMessageBox::error(0, i18n("Error parsing %1: Required attribute NAME is missing in PARAMETER inside DATASOURCE!").arg(XmlPath)); |
return false; |
} |
} |
break; |
|
case in_root: |
Names = empty; |
break; |
case in_map: |
Names = empty; |
break; |
case in_style: |
Names = empty; |
break; |
case in_rule: |
Names = empty; |
break; |
case in_pointsymbolizer: |
Names = empty; |
break; |
case in_textsymbolizer: |
Names = empty; |
break; |
case in_polygonpatternsymbolizer: |
Names = empty; |
break; |
case in_layer: |
Names = empty; |
break; |
case in_symbolizer: |
Names = empty; |
break; |
case in_shieldsymbolizer: |
Names = empty; |
break; |
case in_linepatternsymbolizer: |
Names = empty; |
break; |
} |
} |
|
i++; |
} |
|
return true; |
} |
|
/* |
* This is called every time an element is closed. |
*/ |
bool render::endElement( const QString&, const QString&, const QString& qName) |
bool SRender::endElement( const QString&, const QString&, const QString& qName) |
{ |
if (qName.toLower() == QString("datasource")) |
Container = in_layer; |
else if (qName.toLower() == QString("layer")) |
{ |
parameters p; |
Container = in_map; |
|
if (Lay->Datasource.type.toLower() == QString("shape")) |
{ |
p["type"] = "shape"; |
p["file"] = Lay->Datasource.file.toAscii().constData(); |
} |
else if (Lay->Datasource.type.toLower() == QString("postgis")) |
{ |
p["type"] = "postgis"; |
p["host"] = Lay->Datasource.host.toAscii().constData(); |
p["user"] = Lay->Datasource.user.toAscii().constData(); |
p["dbname"] = Lay->Datasource.dbname.toAscii().constData(); |
p["table"] = Lay->Datasource.table.toAscii().constData(); |
p["estimate_extent"] = (Lay->Datasource.estimate_extent) ? "true" : "false"; |
p["extent"] = QString("%1,%2,%3,%4").arg(Lay->Datasource.ext_lx).arg(Lay->Datasource.ext_ly).arg(Lay->Datasource.ext_rx).arg(Lay->Datasource.ext_ry).toAscii().data(); |
} |
else |
{ |
cerr << "Warning: Layer with no source! Ingnoring!" << endl; |
return true; |
} |
|
Layer lyr(Lay->name.toAscii().data()); |
lyr.set_datasource(datasource_cache::instance()->create(p)); |
lyr.setActive(Lay->status); |
|
if (!Lay->srs.isEmpty()) |
lyr.set_srs(Lay->srs.toAscii().constData()); |
|
// Add the styles |
for (int i = 0; i < Lay->Styles.size(); i++) |
lyr.add_style(Lay->Styles.at(i).toAscii().constData()); |
|
m.addLayer(lyr); |
} |
else if (qName.toLower() == QString("map")) |
{ |
color col; |
|
Container = in_root; |
col.set_bgr(MapPars.bgcolor); |
m.set_background(col); |
m.set_buffer_size(MapPars.buf_size); |
ControlSet = true; |
} |
else if (qName.toLower() == QString("pointsymbol") || |
qName.toLower() == QString("linesymbol") || |
qName.toLower() == QString("polygonsymbol") || |
qName.toLower() == QString("textsymbol") || |
qName.toLower() == QString("polygonpatternsymbol") || |
qName.toLower() == QString("shieldsymbol") || |
qName.toLower() == QString("linepatternsymbol") || |
qName.toLower() == QString("filter") || |
qName.toLower() == QString("maxscaledenominator") || |
qName.toLower() == QString("minscaledenominator")) |
Container = in_rule; |
else if (qName.toLower() == QString("rule")) |
Container = in_style; |
else if (qName.toLower() == QString("style")) |
{ |
Container = in_map; |
feature_type_style style; |
|
if (Style->rule) |
{ |
rule_type rule; |
Rule = Style->rule; |
|
while (Rule) |
{ |
if (Rule->minscale >= 0.0) |
rule.set_min_scale(Rule->minscale); |
|
if (Rule->maxscale >= 0.0) |
rule.set_max_scale(Rule->maxscale); |
|
if (!Rule->filter.isEmpty()) |
rule.set_filter(create_filter(Rule->filter.toAscii().data())); |
|
LineSymbolizer = Rule->LineSymbolizer; |
|
while (LineSymbolizer) |
{ |
stroke st; |
color col; |
col.set_bgr(LineSymbolizer->stroke); |
|
st.set_color (col); |
st.set_width (LineSymbolizer->stroke_width); |
|
if (!LineSymbolizer->stroke_linejoin.isEmpty()) |
{ |
if (LineSymbolizer->stroke_linejoin.toLower() == QString("miter")) |
st.set_line_join (mapnik::MITER_JOIN); |
else if (LineSymbolizer->stroke_linejoin.toLower() == QString("miter_revert") || |
LineSymbolizer->stroke_linejoin.toLower() == QString("miter-revert")) |
st.set_line_join (mapnik::MITER_REVERT_JOIN); |
else if (LineSymbolizer->stroke_linejoin.toLower() == QString("round")) |
st.set_line_join (mapnik::ROUND_JOIN); |
else if (LineSymbolizer->stroke_linejoin.toLower() == QString("bevel")) |
st.set_line_join (mapnik::BEVEL_JOIN); |
else |
{ |
cerr << "Error parsing " << XmlPath.toAscii().data() << ": Unknown >>line_join<< \"" << LineSymbolizer->stroke_linejoin.toAscii().data() << "\" --> ignoring!" << endl; |
LineSymbolizer = LineSymbolizer->next; |
continue; |
} |
} |
|
if (!LineSymbolizer->stroke_linecap.isEmpty()) |
{ |
if (LineSymbolizer->stroke_linecap.toLower() == QString("butt")) |
st.set_line_cap (mapnik::BUTT_CAP); |
else if (LineSymbolizer->stroke_linecap.toLower() == QString("square")) |
st.set_line_cap (mapnik::SQUARE_CAP); |
else if (LineSymbolizer->stroke_linecap.toLower() == QString("round")) |
st.set_line_cap (mapnik::ROUND_CAP); |
else |
{ |
cerr << "Error parsing " << XmlPath.toAscii().data() << ": Unknown >>line_cap<< \"" << LineSymbolizer->stroke_linecap.toAscii().data() << "\" --> ignoring!" << endl; |
LineSymbolizer = LineSymbolizer->next; |
continue; |
} |
} |
|
st.add_dash(LineSymbolizer->stroke_dasharray[0], LineSymbolizer->stroke_dasharray[1]); |
st.set_opacity(LineSymbolizer->stroke_opacity); |
rule.append(line_symbolizer(st)); |
LineSymbolizer = LineSymbolizer->next; |
} |
|
PointSymbolizer = Rule->PointSymbolizer; |
|
while (PointSymbolizer) |
{ |
if (PointSymbolizer->file.length() == 0 || PointSymbolizer->width == 0 || PointSymbolizer->height == 0) |
{ |
cerr << "Warning parsing " << XmlPath.toAscii().data() << ": Ignoring empty POINTSYMBOLIZER!" << endl; |
break; |
} |
|
point_symbolizer ps(PointSymbolizer->file.toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height); |
ps.set_allow_overlap (PointSymbolizer->allow_overlap); |
rule.append(ps); |
PointSymbolizer = PointSymbolizer->next; |
} |
|
PolygonSymbolizer = Rule->PolygonSymbolizer; |
|
while (PolygonSymbolizer) |
{ |
color col; |
col.set_bgr(PolygonSymbolizer->fill); |
|
polygon_symbolizer ps(col); |
ps.set_opacity(PolygonSymbolizer->fill_opacity); |
rule.append(ps); |
PolygonSymbolizer = PolygonSymbolizer->next; |
} |
|
TextSymbolizer = Rule->TextSymbolizer; |
|
while (TextSymbolizer) |
{ |
color col; |
col.set_bgr(TextSymbolizer->fill); |
|
text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col); |
ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius); |
ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width); |
ts.set_max_char_angle_delta(TextSymbolizer->dy); |
ts.set_displacement(TextSymbolizer->mindistance, TextSymbolizer->maxdistance); |
rule.append(ts); |
TextSymbolizer = TextSymbolizer->next; |
} |
|
PolygonPatternSymbolizer = Rule->PolygonPatternSymbolizer; |
|
while (PolygonPatternSymbolizer) |
{ |
// FIXME: The file name must be variable and KDE like!! |
rule.append(polygon_pattern_symbolizer(PolygonPatternSymbolizer->file.toAscii().data(), |
getTypeText(PolygonPatternSymbolizer->type), |
PolygonPatternSymbolizer->width, |
PolygonPatternSymbolizer->height)); |
PolygonPatternSymbolizer = PolygonPatternSymbolizer->next; |
} |
|
ShieldSymbolizer = Rule->ShieldSymbolizer; |
|
while (ShieldSymbolizer) |
{ |
color col; |
col.set_bgr(ShieldSymbolizer->fill); |
// FIXME: The file name must be variable and KDE like!! |
shield_symbolizer ss(ShieldSymbolizer->name.toAscii().data(), |
ShieldSymbolizer->face_name.toAscii().data(), |
ShieldSymbolizer->size, col, |
ShieldSymbolizer->file.toAscii().data(), |
getTypeText(ShieldSymbolizer->type), |
ShieldSymbolizer->width, ShieldSymbolizer->height); |
ss.set_label_placement((ShieldSymbolizer->placement.toLower() == QString("point")) ? mapnik::POINT_PLACEMENT : mapnik::LINE_PLACEMENT); |
ss.set_displacement(ShieldSymbolizer->mindistance, ShieldSymbolizer->maxdistance); |
rule.append(ss); |
ShieldSymbolizer = ShieldSymbolizer->next; |
} |
|
LinePatternSymbolizer = Rule->LinePatternSymbolizer; |
|
while (LinePatternSymbolizer) |
{ |
// FIXME: The file name must be variable and KDE like!! |
rule.append(line_pattern_symbolizer(LinePatternSymbolizer->file.toAscii().data(), |
getTypeText(LinePatternSymbolizer->type), |
LinePatternSymbolizer->width, |
LinePatternSymbolizer->height)); |
LinePatternSymbolizer = LinePatternSymbolizer->next; |
} |
|
style.add_rule(rule); |
Rule = Rule->next; |
} |
} |
|
// Add style to map |
m.insert_style(Style->name.toAscii().data(), style); |
} |
|
return true; |
} |
|
/* |
442,18 → 1068,109 |
* The reader calls this function when it has parsed a chunk of character data |
* - either normal character data or character data inside a CDATA section. |
*/ |
bool render::characters (const QString& ch) |
bool SRender::characters (const QString& ch) |
{ |
if (ch.length() == 0 || ch.at(0) == QChar('\n')) |
return true; |
|
if (Container == in_rule && Rule) |
{ |
if (Field == FLD_FILTER) |
Rule->filter = ch; |
else if (Field == FLD_MAXSCALE) |
Rule->maxscale = ch.toDouble(); |
else if (Field == FLD_MINSCALE) |
Rule->minscale = ch.toDouble(); |
} |
else if (Container == in_linesymbolizer && LineSymbolizer) |
{ |
if (Field == FLD_CSSPARAMETER) |
{ |
if (Names == stroke_stroke) |
LineSymbolizer->stroke = colorToUInt(ch); |
else if (Names == stroke_width) |
LineSymbolizer->stroke_width = ch.toDouble(); |
else if (Names == stroke_linejoin) |
LineSymbolizer->stroke_linejoin = ch; |
else if (Names == stroke_linecap) |
LineSymbolizer->stroke_linecap = ch; |
else if (Names == stroke_opacity) |
LineSymbolizer->stroke_opacity = ch.toDouble(); |
else if (Names == stroke_dasharray) |
{ |
int pos; |
QString arr = ch; |
QStringList list; |
|
list = arr.split(",", QString::SkipEmptyParts); |
|
for (pos = 0; pos < list.size() && pos < 10; pos++) |
{ |
LineSymbolizer->stroke_dasharray[pos] = list.at(pos).toDouble(); |
pos++; |
} |
|
LineSymbolizer->stroke_anz = pos; |
} |
} |
} |
else if (Container == in_polygonsymbolizer && PolygonSymbolizer) |
{ |
if (Field == FLD_CSSPARAMETER) |
{ |
if (Names == fill) |
PolygonSymbolizer->fill = colorToUInt(ch); |
else if (Names == fill_opacity) |
PolygonSymbolizer->fill_opacity = ch.toDouble(); |
} |
} |
else if (Container == in_layer && Lay) |
{ |
if (Field == FLD_STYLENAME) |
Lay->Styles << ch; |
} |
else if (Container == in_datasource && Lay) |
{ |
if (Field == FLD_PARAMETER) |
{ |
if (Names == type) |
Lay->Datasource.type = ch; |
else if (Names == file) |
Lay->Datasource.file = ch; |
else if (Names == host) |
Lay->Datasource.host = ch; |
else if (Names == user) |
Lay->Datasource.user = ch; |
else if (Names == dbname) |
Lay->Datasource.dbname = ch; |
else if (Names == table) |
Lay->Datasource.table = ch; |
else if (Names == estimate_extent) |
Lay->Datasource.estimate_extent = getBool(ch); |
else if (Names == extent) |
{ |
QString arr = ch; |
QStringList list; |
list = arr.split(","); |
Lay->Datasource.ext_lx = list.at(0).toDouble(); |
Lay->Datasource.ext_ly = list.at(1).toDouble(); |
Lay->Datasource.ext_rx = list.at(2).toDouble(); |
Lay->Datasource.ext_ry = list.at(3).toDouble(); |
} |
} |
} |
|
return true; |
} |
|
QString render::getKey (int pos) |
QString SRender::getKey (int pos) |
{ |
int i = 0; |
|
while (keys[i].id > 0) |
while (token[i].id > 0) |
{ |
if (keys[i].id == pos) |
return keys[i].name; |
if (token[i].id == pos) |
return token[i].name; |
|
i++; |
} |
461,219 → 1178,208 |
return QString::null; |
} |
|
bool render::getMap (double lx, double ly, double rx double ry) |
TYPES SRender::getType(QString ty) |
{ |
int width, height; |
if (ty.toLower() == QString("png")) |
return type_png; |
else if (ty.toLower() == QString("gif")) |
return type_gif; |
else if (ty.toLower() == QString("jpg")) |
return type_jpg; |
else if (ty.toLower() == QString("xpm")) |
return type_xpm; |
else if (ty.toLower() == QString("bmp")) |
return type_bmp; |
else if (ty.toLower() == QString("tif") || ty.toLower() == QString("tiff")) |
return type_tif; |
|
datasource_cache::instance()->register_datasources(MAPNIK_PLUGIN_PATH + "/"); |
freetype_engine::register_font(MAPNIK_FONTS + "/DejaVuSans.ttf"); |
return type_png; |
} |
|
width = label.width(); |
height = label.height(); |
char *grTypes[] = { (char *)"png", (char *)"gif", (char *)"jpg", (char*)"xpm", |
(char *)"bmp", (char *)"tif" }; |
|
Map m(width, height, "+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs"); |
m.set_background(color_factory::from_string("white")); |
char *SRender::getTypeText(TYPES type) |
{ |
switch (type) |
{ |
case type_png: return grTypes[0]; break; |
case type_gif: return grTypes[1]; break; |
case type_jpg: return grTypes[2]; break; |
case type_xpm: return grTypes[3]; break; |
case type_bmp: return grTypes[4]; break; |
case type_tif: return grTypes[5]; break; |
} |
|
// create styles |
// world1 |
feature_type_style world1_style; |
addRule(&world1_style, 0, 6000000.0, 250000000000.0, Color(0xf2, 0xef, 0xe9), Color(0xb5, 0xd0, 0xd0), 0.5, 0, 0, 0); |
return 0; |
} |
|
// world |
feature_type_style world_style; |
addRule(&world_style, 0, 600000.0, 6000000.0, Color(0xf2, 0xef, 0xe9), 0, 0.0, 0, 0, 0); |
bool SRender::getBool(QString b) |
{ |
if (b.toLower() == QString("true") || |
b.toLower() == QString("on") || |
b.toLower() == QString("1") || |
b.toLower() == QString("yes") || |
b.toLower() == QString("t") || |
b.toLower() == QString("y")) |
return true; |
|
// coast_poly |
feature_type_style coast_poly_style; |
addRule(&coas_poly_style, 0, -1.0, 600000.0, Color(0xf2, 0xef, 0xe9), 0, 0.0, 0, 0, 0); |
return false; |
} |
|
// builtup |
feature_type_style builtup_style; |
addRule(&builtup_style, 0, 500000.0, 2500000.0, Color(0x0d, 0x0d, 0x0d), 0, 0.0, 0, 0, 0); |
bool SRender::getMap (double lx, double ly, double rx, double ry) |
{ |
int width, height, pid; |
QXmlSimpleReader reader; |
QString hv0; |
QFile file(XmlPath); |
|
// places |
feature_type_style places_style; |
text_symbolizer places_ts = addTextSymbolizer("place_name", "DejaVu Sans Book", 10, Color(0x04, 0x04, 0x04), 1, 0.0); |
places_style.append(places_ts); |
addRule(&places_style, 0, 10000000.0, 50000000.0, 0, 0, 0.0, 0, 0, 0); |
hv0 = pluginPath + "/"; |
datasource_cache::instance()->register_datasources(hv0.toAscii().data()); |
hv0 = fontPath + "/DejaVuSans.ttf"; |
freetype_engine::register_font(hv0.toAscii().data()); |
|
// stations |
feature_type_style stations_style; |
addRulePoint(&stations_style, "[railway]='station'", 25000.0, 250000.0, 0, 0, 0.0, QString("station_small.png"), 5, 5); |
addRulePoint(&stations_style, "[railway]='station'", -1.0, 25000.0, 0, 0, 0.0, QString("station.png", 9, 9); |
addRulePoint(&stations_style, "[railway]='halt' or [railway]='tram_stop'", -1.0, 100000.0, 0, 0, 0.0, QString("halt.png"), 3, 3); |
width = label->width(); |
height = label->height(); |
|
text_symbolizer stations_ts = addTextSymbolizer("name", "DejaVu Sans Bold", 8, Color(0, 0, 0), 1, 0, -8.0); |
stations_style.append(stations_ts); |
addRulePoint(&stations_style, "[railway]='halt'", 25000.0, 50000.0, 0, 0, 0.0, 0, 0, 0, 0); |
m.setWidth(width); |
m.setHeight(height); |
|
text_symbolizer stations_ts1 = addTextSymbolizer("name", "DejaVu Sans Bold", 10, Color(0, 0, 0), 1, 0, -14.0); |
stations_style.append(stations_ts1); |
addRule(&stations_style, "[railway] ='halt'", -1.0, 25000.0, 0, 0, 0.0, 0, 0, 0); |
if (!ControlSet) // Initialize the map? |
{ |
QXmlInputSource source (&file); |
reader.setContentHandler (this); |
reader.parse (source); |
} |
|
text_symbolizer stations_ts2 = addTextSymbolizer("name", "DejaVu Sans Bold", 9, Color(0, 0, 0), 1, 0, -8.0); |
stations_style.append(stations_ts2); |
addRule(&stations_style, "[railway]='station'", 25000.0, 50000.0, 0, 0, 0.0, 0, 0, 0); |
// First we use Mapnik to create the map |
cout << lx << ", " << ly << ", " << rx << ", " << ry << endl; |
//cout << DEG2RAD(lx) << ", " << DEG2RAD(ly) << ", " << DEG2RAD(rx) << ", " << DEG2RAD(ry) << endl; |
m.zoomToBox(Envelope<double>(lx, ly, rx, ry)); |
Image32 buf(m.getWidth(), m.getHeight()); |
agg_renderer<Image32> ren(m, buf); |
ren.apply(); |
// Create a unique file name |
pid = getpid(); |
hv0.sprintf("/var/tmp/SportWatcher_%d", pid); |
save_to_file<ImageData32>(buf.data(), hv0.toAscii().data(), "png"); |
|
text_symbolizer stations_ts3 = addTextSymbolizer("name", "DejaVu Sans Bold", 12, Color(0, 0, 0), 1, 0, -14.0); |
stations_style.append(stations_ts3); |
addRule(&stations_style, "[railway]='station'", -1.0, 25000.0, 0, 0, 0.0, 0, 0, 0); |
addRulePoint(&stations_style, "[railway]='level_crossing'", 10000.0, 50000.0, 0, 0, 0.0, QString("level_crossing.png"), 7, 7); |
// Now we move the image into a QPixmap |
QPixmap pm; |
pm.load(hv0); |
unlink(hv0.toAscii().data()); // delete the temporary file |
label->setPixmap(pm); |
return true; |
} |
|
// leisure |
feature_type_style leisure_style; |
RULE *SRender::getLastRule(RULE *first) |
{ |
RULE *akt = first; |
|
addRule(&leisure_style, "[man_made] = 'pier'", -1.0, 100000.0, Color(0xed, 0xed, 0xed), color_factory::from_string("grey"), 0.3, 0, 0, 0); |
addRule(&leisure_style, "[highway] = 'residential'", -1.0, 50000.0, Color(255, 255, 255), Color(0x09, 0x09, 0x09), 1.0, 0, 0, 0); |
addRule(&leisure_style, "[highway] = 'pedestrian'", -1.0, 50000.0, Color(0xed, 0xed, 0xed), color_factory::from_string("grey"), 0.5, 0, 0, 0); |
addRule(&leisure_style, "[leisure] = 'playground'", -1.0, 100000.0, Color(0xcc, 0xff, 0xff), Color(0x06, 0x06, 0x06), 0.3, 0, 0, 0); |
addRule(&leisure_style, "[tourism] = 'attraction'", -1.0, 100000.0, Color(0xf2, 0xca, 0xea), 0, -1.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'quarry'", -1.0, 500000.0, 0, color_factory::from_string("grey"), 0.5, QString("quarry2.png"), 30, 30); |
addRule(&leisure_style, "[leisure] = 'nature_reserve' or [landuse] = 'vineyard'", 100000.0, 1000000.0, Color(0xab, 0xdf, 0x96), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'vineyard'", 20000.0, 100000.0, 0, 0, 0.0, QString("vineyard.png"), 19, 21); |
addRule(&leisure_style, "[landuse] = 'vineyard'", -1.0, 100000.0, 0, 0, 0.0, QString("vineyard.png"), 29, 29); |
addRule(&leisure_style, "[leisure] = 'nature_reserve'", 50000.0, 100000.0, 0, 0, 0.0, QString("nature_reserve.png"), 21, 24); |
addRule(&leisure_style, "[leisure] = 'nature_reserve'", -1.0, 50000.0, 0, 0, 0.0, QString("nature_reserve2.png"), 42, 48); |
addRule(&leisure_style, "[landuse] = 'cemetery'", 20000.0, 1000000.0, Color(0xaa, 0xcb, 0xaf), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'residential'", 1000.0, 1000000.0, Color(0x0d, 0x0d, 0x0d), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[military] = 'barracks'", 1000.0, 1000000.0, Color(0xff, 0x8f, 0x8f), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[military] = 'danger_area'", 500000.0, 2000000.0, color_factory::from_string("pink"), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity 0.3 is missing! |
addRule(&leisure_style, "[military] = 'danger_area'", 1000.0, 500000.0, 0, 0, 0.0, QString("danger.png"), 30, 30); |
addRule(&leisure_style, "[landuse] = 'cemetery'", -1.0, 50000.0, 0, 0, 0.0, QString("grave_yard.png"), 16, 16); |
addRule(&leisure_style, "[landuse] = 'meadow'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[leisure] = 'park'", -1.0, 1000000.0, Color(0xb6, 0xfd, 0xb6), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[tourism] = 'zoo'", -1.0, 1000000.0, 0, 0, 0.0, QString("zoo.png"), 21, 24); |
addRule(&leisure_style, "[leisure] = 'common'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[leisure] = 'garden'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[leisure] = 'golf_course'", -1.0, 1000000.0, Color(0xb5, 0xe3, 0xb5), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'allotments'", -1.0, 1000000.0, Color(0xc8, 0xb0, 0x84), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'forest'", 50000.0, 2000000.0, Color(0x8d, 0xc5, 0x6c), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'forest'", -1.0, 50000.0, 0, 0, 0.0, QString("forest.png"), 21, 24); |
addRule(&leisure_style, "[landuse] = 'farm'", -1.0, 2000000.0, Color(0xea, 0xd8, 0xbd), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'recreation_ground'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'village_green'", -1.0, 500000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'retail'", -1.0, 1000000.0, Color(0xf1, 0xda, 0xda), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'retail'", -1.0, 25000.0, 0, color_factory::from_string("red"), 0.3, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'industrial'", -1.0, 1000000.0, Color(0xff, 0xae, 0xb9), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[power] = 'station'", 200000.0, 1000000.0, Color(0x0b, 0x0b, 0x0b), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[power] = 'station'", -1.0, 200000.0, Color(0x0b, 0x0b, 0x0b), Color(0x05, 0x05, 0x05), 0.4, 0, 0, 0); |
addRule(&leisure_style, "[power] = 'sub_station'", -1.0, 100000.0, Color(0x0b, 0x0b, 0x0b), Color(0x05, 0x05, 0x05), 0.4, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'commercial'", -1.0, 1000000.0, Color(0xef, 0xc8, 0xc8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'brownfield' or [landuse]='landfill'", -1, 1000000.0, Color(0x9d, 0x9d, 0x6c), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[natural] = 'wood' or [landuse] = 'wood'", -1.0, 1000000.0, Color(0xae, 0xd1, 0xa0), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[natural] = 'heath'", -1.0, 1000000.0, Color(0xff, 0xff, 0xc0), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[landuse] = 'basin'", -1.0, 5000000.0, Color(0xb5, 0xd0, 0xd0), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[amenity] = 'university' or [amenity] = 'college' or [amenity] = 'school' or [amenity]='hospital'", -1.0, 1000000.0, Color(0xf0, 0xf0, 0xd8), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[amenity] = 'university' or [amenity] = 'college' or [amenity] = 'school' or [amenity]='hospital'", -1.0, 250000.0, 0, color_factory::from_string("brown"), 0.3, 0, 0, 0); |
addRule(&leisure_style, "[amenity] = 'parking'", -1.0, 1000000.0, Color(0xf7, 0xef, 0xb7), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[amenity] = 'parking'", -1.0, 25000.0, 0, Color(0xee, 0xee, 0xd1), 0.3, 0, 0, 0); |
addRule(&leisure_style, "[railway] = 'station' or [building] = 'station'", -1.0, 1000000.0, Color(0xff, 0xf6, 0x8f), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity = 0.5 is missing! |
addRule(&leisure_style, "[building] = 'supermarket'", -1.0, 1000000.0, color_factory::from_string("pink"), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity = 0.5 is missing! |
addRule(&leisure_style, "[building] <> 'station' and [building] <> 'supermarket' and [building] <> ''", -1.0, 1000000.0, Color(0xcc, 0x99, 0x99), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[amenity] = 'place_of_worship'", 20000.0, 1000000.0, Color(0x07, 0x07, 0x07), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity = 0.5 is missing! |
addRule(&leisure_style, "[amenity] = 'place_of_worship'", -1.0, 20000.0, Color(0x07, 0x07, 0x07), Color(0x01, 0x01, 0x01), 0.3, 0, 0, 0); |
addRule(&leisure_style, "[leisure] = 'sports_centre' or [leisure]='stadium' or [leisure]='track'", -1.0, 1000000.0, Color(0x33, 0xcc, 0x99), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[leisure] = 'pitch'", -1.0, 1000000.0, Color(0x8a, 0xd3, 0xaf), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[aeroway] = 'terminal'", -1.0, 200000.0, Color(0xcc, 0x99, 0xff), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[aeroway] = 'terminal'", -1.0, 50000.0, 0, Color(0x33, 0x00, 0x66), 0.2, 0, 0, 0); |
addRule(&leisure_style, "[aeroway] = 'apron'", -1.0, 200000.0, Color(0xf0, 0xe0, 0xff), 0, 0.0, 0, 0, 0); |
addRule(&leisure_style, "[natural] = 'beach'", -1.0, 100000.0, 0, 0, 0.0, QString("beach.png"), 10, 10); |
while (akt) |
{ |
if (!akt->next) |
return akt; |
|
akt = akt->next; |
} |
|
return 0; |
} |
|
void render::addRule (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph) |
POINTSYMBOLIZER *SRender::getLastPointSymbolizer(POINTSYMBOLIZER *first) |
{ |
rule_type rule; |
POINTSYMBOLIZER *akt = first; |
|
if (minscale >= 0.0) |
rule.set_min_scale(minscale); |
while (akt) |
{ |
if (!akt->next) |
return akt; |
|
if (maxscale >= 0.0) |
rule.set_max_scale(maxscale); |
akt = akt->next; |
} |
|
if (pattern && pw > 0 && ph > 0) |
return 0; |
} |
|
LINESYMBOLIZER *SRender::getLastLineSymbolizer(LINESYMBOLIZER *first) |
{ |
LINESYMBOLIZER *akt = first; |
|
while (akt) |
{ |
QString ptf = KStandardDirs::findRessource("icon", pattern); |
if (!akt->next) |
return akt; |
|
rule.append(polygon_pattern_symbolizer(ptf.toAscii().data(), "png", pw, ph)); |
akt = akt->next; |
} |
|
if (filter) |
rule.set_filter(create_filter(filter)); |
return 0; |
} |
|
if (polcol) |
rule.append(polygon_symbolizer(polcol)); |
POLYGONSYMBOLIZER *SRender::getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first) |
{ |
POLYGONSYMBOLIZER *akt = first; |
|
if (symcol) |
while (akt) |
{ |
stroke stk (symcol); |
if (!akt->next) |
return akt; |
|
if (symwidth >= 0.0) |
stk.set_width(0.3); |
|
rule.append(line_symbolizer(stk)); |
akt = akt->next; |
} |
|
fts.add_rule(rule); |
return 0; |
} |
|
void render::addRulePoint (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph) |
TEXTSYMBOLIZER *SRender::getLastTextSymbolizer(TEXTSYMBOLIZER *first) |
{ |
rule_type rule; |
TEXTSYMBOLIZER *akt = first; |
|
if (minscale >= 0.0) |
rule.set_min_scale(minscale); |
|
if (maxscale >= 0.0) |
rule.set_max_scale(maxscale); |
|
if (pattern && pw > 0 && ph > 0) |
while (akt) |
{ |
QString ptf = KStandardDirs::findRessource("icon", pattern); |
if (!akt->next) |
return akt; |
|
rule.append(point_symbolizer(ptf.toAscii().data(), "png", pw, ph)); |
akt = akt->next; |
} |
|
if (filter) |
rule.set_filter(create_filter(filter)); |
return 0; |
} |
|
if (polcol) |
rule.append(polygon_symbolizer(polcol)); |
POLYGONPATTERNSYMBOLIZER *SRender::getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first) |
{ |
POLYGONPATTERNSYMBOLIZER *akt = first; |
|
if (symcol) |
while (akt) |
{ |
stroke stk (symcol); |
if (!akt->next) |
return akt; |
|
if (symwidth >= 0.0) |
stk.set_width(0.3); |
|
rule.append(line_symbolizer(stk)); |
akt = akt->next; |
} |
|
fts.add_rule(rule); |
return 0; |
} |
|
text_symbolizer &render::addTextSymbolizer (char *name, char *font, int size, Color &col, int radius, int wrap, double dy) |
SHIELDSYMBOLIZER *SRender::getLastShieldSymbolizer(SHIELDSYMBOLIZER *first) |
{ |
text_symbolizer ts(name, font, size, Color(0, 0, 0)); |
SHIELDSYMBOLIZER *akt = first; |
|
if (vol && radius > 0) |
while (akt) |
{ |
ts.set_halo_fill(halo); |
ts.set_halo_radius(radius); |
if (!akt->next) |
return akt; |
|
akt = akt->next; |
} |
|
if (dy < 0.0) |
ts.set_max_char_angle_delta(dy); |
|
if (wrap >= 0) |
ts.set_wrap_width(wrap); |
|
return &ts; |
return 0; |
} |
|
RULE *render::getLastRule(RULE *first) |
LINEPATTERNSYMBOLIZER *SRender::getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first) |
{ |
RULE *akt = first; |
LINEPATTERNSYMBOLIZER *akt = first; |
|
while (akt) |
{ |
686,13 → 1392,13 |
return 0; |
} |
|
POINTSYMBOLIZER *render::getLastPointSymbolizer(POINTSYMBOLIZER *first) |
STYLE *SRender::findStyle(QString name) |
{ |
POINTSYMBOLIZER *akt = first; |
STYLE *akt = firstStyle; |
|
while (akt) |
{ |
if (!akt->next) |
if (akt->name.toLower() == name.toLower()) |
return akt; |
|
akt = akt->next; |
700,3 → 1406,160 |
|
return 0; |
} |
|
unsigned SRender::colorToUInt(QString col) |
{ |
QColor qc(col); |
|
return (qc.red() * 65536) + (qc.green() * 256) + qc.blue(); |
} |
|
STYLE *SRender::allocStyle() |
{ |
STYLE *St = new STYLE; |
|
St->name.clear(); |
St->rule = 0; |
St->next = 0; |
return St; |
} |
|
RULE *SRender::allocRule() |
{ |
RULE *Ru = new RULE; |
|
Ru->maxscale = 0; |
Ru->minscale = 0; |
Ru->filter.clear(); |
Ru->LineSymbolizer = 0; |
Ru->PolygonSymbolizer = 0; |
Ru->TextSymbolizer = 0; |
Ru->PointSymbolizer = 0; |
Ru->PolygonPatternSymbolizer = 0; |
Ru->ShieldSymbolizer = 0; |
Ru->LinePatternSymbolizer = 0; |
Ru->next = 0; |
return Ru; |
} |
|
LAYER *SRender::allocLayer() |
{ |
LAYER *La = new LAYER; |
|
La->name.clear(); // The unique name |
La->status = false; // Is it active? |
La->srs.clear(); // Projection |
La->Datasource.type.clear(); |
La->Datasource.file.clear(); |
La->Datasource.host.clear(); |
La->Datasource.user.clear(); |
La->Datasource.dbname.clear(); |
La->Datasource.table.clear(); |
La->Datasource.estimate_extent = false; |
La->Datasource.ext_lx = 0.0; |
La->Datasource.ext_ly = 0.0; |
La->Datasource.ext_rx = 0.0; |
La->Datasource.ext_ry = 0.0; |
La->next = 0; |
return La; |
} |
|
LINEPATTERNSYMBOLIZER *SRender::allocLinePatternSymbolizer() |
{ |
LINEPATTERNSYMBOLIZER *lps = new LINEPATTERNSYMBOLIZER; |
|
lps->file.clear(); |
lps->type = type_png; // enum TYPES |
lps->width = 0.0; |
lps->height = 0.0; |
lps->next = 0; |
return lps; |
} |
|
SHIELDSYMBOLIZER *SRender::allocShieldSymbolizer() |
{ |
SHIELDSYMBOLIZER *ss = new SHIELDSYMBOLIZER; |
|
ss->name.clear(); |
ss->face_name.clear(); |
ss->size = 0.0; |
ss->fill = 0; // Color |
ss->placement.clear(); |
ss->file.clear(); |
ss->type = type_png; // enum TYPES |
ss->width = 0.0; |
ss->height = 0.0; |
ss->mindistance = 0.0; |
ss->maxdistance = 0.0; |
ss->next = 0; |
return ss; |
} |
|
POLYGONPATTERNSYMBOLIZER *SRender::allocPolygonPatternSymbolizer() |
{ |
POLYGONPATTERNSYMBOLIZER *pps = new POLYGONPATTERNSYMBOLIZER; |
|
pps->file.clear(); |
pps->type = type_png; // enum TYPES |
pps->width = 0.0; |
pps->height = 0.0; |
pps->allow_overlap = false; |
pps->next = 0; |
return pps; |
} |
|
POINTSYMBOLIZER *SRender::allocPointSymbolizer() |
{ |
POINTSYMBOLIZER *ps = new POINTSYMBOLIZER; |
|
ps->file.clear(); |
ps->type = type_png; // enum TYPES |
ps->width = 0.0; |
ps->height = 0.0; |
ps->allow_overlap = false; |
ps->next = 0; |
return ps; |
} |
|
TEXTSYMBOLIZER *SRender::allocTextSymbolizer() |
{ |
TEXTSYMBOLIZER *ts = new TEXTSYMBOLIZER; |
|
ts->name.clear(); |
ts->face_name.clear(); |
ts->size = 0; |
ts->fill = 0; // Color |
ts->halo_radius = 0; |
ts->wrap_width = 0; |
ts->dy = 0.0; |
ts->mindistance = 0.0; |
ts->maxdistance = 0.0; |
ts->next = 0; |
return ts; |
} |
|
POLYGONSYMBOLIZER *SRender::allocPolygonSymbolizer() |
{ |
POLYGONSYMBOLIZER *ps = new POLYGONSYMBOLIZER; |
|
memset (ps, 0, sizeof(POLYGONSYMBOLIZER)); |
return ps; |
} |
|
LINESYMBOLIZER *SRender::allocLineSymbolizer() |
{ |
LINESYMBOLIZER *ls = new LINESYMBOLIZER; |
|
ls->stroke = 0; // Color |
ls->stroke_width = 0.0; |
ls->stroke_linejoin.clear(); |
ls->stroke_linecap.clear(); |
|
for (int i = 0; i < 10; i++) |
ls->stroke_dasharray[i] = 0.0; |
|
ls->stroke_anz = 0; // number of entries in dasharray |
ls->stroke_opacity = 0.0; |
ls->next = 0; |
return ls; |
} |