42,6 → 42,7 |
#define CON_DATASOURCE 109 |
#define CON_SHIELDSYMBOLIZER 110 |
#define CON_LINEPATTERNSYMBOLIZER 111 |
#define CON_ELSEFILTER 112 |
|
#define FLD_FILTER 200 |
#define FLD_CSSPARAMETER 201 |
68,15 → 69,16 |
#define ATT_STATUS 315 |
#define ATT_SRS 316 |
#define ATT_DX 317 |
#define ATT_ALIGNMENT 318 |
|
#define FIRST_CON 100 |
#define LAST_CON 111 |
#define LAST_CON 112 |
|
#define FIRST_FLD 200 |
#define LAST_FLD 205 |
|
#define FIRST_ATT 300 |
#define LAST_ATT 317 |
#define LAST_ATT 318 |
|
using std::cout; |
using std::cerr; |
97,6 → 99,7 |
{ CON_DATASOURCE, in_datasource, QString("Datasource") }, |
{ CON_SHIELDSYMBOLIZER, in_shieldsymbolizer, QString("ShieldSymbolizer") }, |
{ CON_LINEPATTERNSYMBOLIZER, in_linepatternsymbolizer, QString("LinePatternSymbolizer") }, |
{ CON_ELSEFILTER, in_rule, QString("ElseFilter") }, |
// Fields |
{ FLD_FILTER, in_rule, QString("Filter") }, |
{ FLD_CSSPARAMETER, in_symbolizer, QString("CSSParameter") }, |
123,6 → 126,7 |
{ ATT_ALLOWOVERLAP, in_symbolizer, QString("allow_overlap") }, |
{ ATT_STATUS, in_layer, QString("status") }, |
{ ATT_SRS, in_layer, QString("srs") }, |
{ ATT_ALIGNMENT, in_symbolizer, QString("alignment") }, |
{ 0, in_root, QString::null } |
}; |
|
143,6 → 147,7 |
LinePatternSymbolizer = 0; |
_lx = _ly = 180.0; |
_rx = _ry = -180.0; |
__map_type = MAP_SHAPE; // The default map type |
// This is true, when a XML file was parsed successfully |
ControlSet = false; |
|
407,8 → 412,30 |
Rule->next = allocRule(); |
Rule = Rule->next; |
} |
|
if ((index = att.index(QString("name"))) != -1) |
{ |
Rule->name = att.value(index); |
Rule->rl.set_name(Rule->name.toAscii().data()); |
} |
|
if ((index = att.index(QString("title"))) != -1) |
{ |
Rule->title = att.value(index); |
Rule->rl.set_title(Rule->title.toAscii().data()); |
} |
break; |
|
case CON_ELSEFILTER: |
Container = in_elsefilter; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1, line %2: Open ELSEFILTER outside of a RULE!").arg(XmlPath).arg(XmlLine)); |
return false; |
} |
break; |
|
case CON_LAYER: |
Container = in_layer; |
|
438,6 → 465,18 |
|
if ((index = att.index(QString("maxzoom"))) != -1) |
Lay->maxzoom = att.value(index).toDouble(); |
|
if ((index = att.index(QString("queryable"))) != -1) |
Lay->queryable = getBool(att.value(index)); |
|
if ((index = att.index(QString("title"))) != -1) |
Lay->title = att.value(index); |
|
if ((index = att.index(QString("abstract"))) != -1) |
Lay->abstract = att.value(index); |
|
if ((index = att.index(QString("clear_label_cache"))) != -1) |
Lay->clear_label = getBool(att.value(index)); |
break; |
|
case CON_DATASOURCE: |
479,12 → 518,7 |
PointSymbolizer->height = att.value(index).toDouble(); |
|
if ((index = att.index(QString("allow_overlap"))) != -1) |
{ |
if (att.value(index).toLower() == QString("true")) |
PointSymbolizer->allow_overlap = true; |
else |
PointSymbolizer->allow_overlap = false; |
} |
PointSymbolizer->allow_overlap = getBool(att.value(index)); |
break; |
|
break; |
563,6 → 597,9 |
if ((index = att.index(QString("face_name"))) != -1) |
TextSymbolizer->face_name = att.value(index); |
|
if ((index = att.index(QString("placement"))) != -1) |
TextSymbolizer->placement = att.value(index); |
|
if ((index = att.index(QString("size"))) != -1) |
TextSymbolizer->size = att.value(index).toDouble(); |
|
575,6 → 612,9 |
if ((index = att.index(QString("wrap_width"))) != -1) |
TextSymbolizer->wrap_width = att.value(index).toDouble(); |
|
if ((index = att.index(QString("alignment"))) != -1) |
TextSymbolizer->alignment = att.value(index); |
|
if ((index = att.index(QString("dx"))) != -1) |
TextSymbolizer->dx = att.value(index).toDouble(); |
|
809,6 → 849,12 |
Names = estimate_extent; |
else if (att.value(index).toLower() == QString("extent")) |
Names = extent; |
else if (att.value(index).toLower() == QString("parser")) |
Names = parser__; |
else if (att.value(index).toLower() == QString("url")) |
Names = url; |
else if (att.value(index).toLower() == QString("bbox")) |
Names = bbox; |
} |
else |
{ |
851,6 → 897,9 |
case in_linepatternsymbolizer: |
Names = empty; |
break; |
case in_elsefilter: |
Names = empty; |
break; |
} |
} |
|
872,21 → 921,48 |
parameters p; |
Container = in_map; |
|
if (Lay->Datasource.type.toLower() == QString("shape")) |
if (Lay->Datasource.type.toLower() == QString("shape") && __map_type == MAP_SHAPE) |
{ |
QFileInfo qdi(Lay->Datasource.file); |
QString hv0; |
|
hv0 = qdi.fileName(); |
|
if (shapePath.right(1) == QChar('/')) |
hv0 = shapePath + hv0; |
else |
hv0 = shapePath + "/" + hv0; |
|
p["type"] = "shape"; |
p["file"] = Lay->Datasource.file.toAscii().constData(); |
p["file"] = hv0.toAscii().data(); |
} |
else if (Lay->Datasource.type.toLower() == QString("postgis")) |
else if (Lay->Datasource.type.toLower() == QString("postgis") && __map_type == MAP_GIS) |
{ |
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["host"] = Lay->Datasource.host.toAscii().data(); |
p["user"] = Lay->Datasource.user.toAscii().data(); |
p["dbname"] = Lay->Datasource.dbname.toAscii().data(); |
p["table"] = Lay->Datasource.table.toAscii().data(); |
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 if (Lay->Datasource.type.toAscii() == QString("osm") && __map_type == MAP_OSM) |
{ |
p["type"] = "osm"; |
|
if (Lay->Datasource.parser.length() <= 0) |
p["parser"] = "libxml2"; |
else |
p["parser"] = Lay->Datasource.parser.toAscii().data(); |
|
if (!Lay->Datasource.url.isEmpty() && !Lay->Datasource.bbox.isEmpty()) |
{ |
p["url"] = Lay->Datasource.url.toAscii().data(); |
p["bbox"] = Lay->Datasource.bbox.toAscii().data(); |
} |
else |
p["file"] = shapePath.toAscii().data(); |
} |
else |
{ |
cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Layer with no source! Ingnoring!" << endl; |
894,9 → 970,18 |
} |
|
Layer lyr(Lay->name.toAscii().data()); |
lyr.set_title(Lay->name.toAscii().data()); |
|
if (!Lay->title.isEmpty()) |
lyr.set_title(Lay->title.toAscii().data()); |
|
if (!Lay->abstract.isEmpty()) |
lyr.set_abstract(Lay->abstract.toAscii().data()); |
|
lyr.set_datasource(datasource_cache::instance()->create(p)); |
|
if (!Lay->srs.isEmpty()) |
lyr.set_srs(Lay->srs.toAscii().data()); |
|
if (Lay->minzoom > 0.0) |
lyr.setMinZoom(Lay->minzoom); |
|
903,19 → 988,19 |
if (Lay->maxzoom > 0.0) |
lyr.setMaxZoom(Lay->maxzoom); |
|
if (!Lay->srs.isEmpty()) |
lyr.set_srs(Lay->srs.toAscii().constData()); |
lyr.set_clear_label_cache(Lay->clear_label); |
|
// Add the styles |
for (int i = 0; i < Lay->Styles.size(); i++) |
{ |
if (findStyle (Lay->Styles.at(i)) != 0) |
lyr.add_style(Lay->Styles.at(i).toAscii().constData()); |
lyr.add_style(Lay->Styles.at(i).toAscii().data()); |
else |
cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Style \"" << Lay->Styles.at(i).toAscii().data() << "\" does not exist!" << endl; |
} |
|
lyr.setActive(Lay->status); |
lyr.setQueryable(true); |
m.addLayer(lyr); |
Envelope <double>le(lyr.envelope()); |
setMaxExtent(le.minx(), le.miny(), le.maxx(), le.maxy()); |
943,7 → 1028,7 |
} |
else |
{ |
point_symbolizer ps(PointSymbolizer->file.toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height); |
point_symbolizer ps(findIcon(PointSymbolizer->file).toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height); |
ps.set_allow_overlap (PointSymbolizer->allow_overlap); |
Rule->rl.append(ps); |
} |
1035,21 → 1120,48 |
color col; |
col.set_bgr(TextSymbolizer->fill); |
|
text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col); |
if (TextSymbolizer->name.length() <= 0 || TextSymbolizer->face_name.length() <= 0 || TextSymbolizer->size <= 0) |
cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Empty TEXTSYMBOLIZER found --> ignoring!" << endl; |
else |
{ |
text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col); |
|
if (TextSymbolizer->halo_radius != 0.0) |
ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius); |
if (TextSymbolizer->halo_radius != 0.0) |
ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius); |
|
if (TextSymbolizer->wrap_width != 0.0) |
ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width); |
if (TextSymbolizer->wrap_width != 0.0) |
ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width); |
|
if (TextSymbolizer->mindistance != 0) |
ts.set_label_spacing(TextSymbolizer->mindistance); |
if (TextSymbolizer->mindistance != 0) |
ts.set_label_spacing(TextSymbolizer->mindistance); |
|
if (TextSymbolizer->dx != 0 || TextSymbolizer->dy != 0) |
ts.set_displacement(TextSymbolizer->dx, TextSymbolizer->dy); |
if (!TextSymbolizer->placement.isEmpty()) |
{ |
if (TextSymbolizer->placement.toLower() == QString("point")) |
ts.set_label_placement(mapnik::POINT_PLACEMENT); |
else if (TextSymbolizer->placement.toLower() == QString("line")) |
ts.set_label_placement(mapnik::LINE_PLACEMENT); |
else |
cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Unknown >>label placement<< \"" << TextSymbolizer->placement.toAscii().data() << "\" --> ignoring!" << endl; |
} |
|
Rule->rl.append(ts); |
if (!TextSymbolizer->alignment.isEmpty()) |
{ |
if (TextSymbolizer->alignment.toLower() == QString("top")) |
ts.set_vertical_alignment(mapnik::TOP); |
else if (TextSymbolizer->alignment.toLower() == QString("middle")) |
ts.set_vertical_alignment(mapnik::MIDDLE); |
else if (TextSymbolizer->alignment.toLower() == QString("bottom")) |
ts.set_vertical_alignment(mapnik::BOTTOM); |
else |
cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Unknown >>vertical placement<< \"" << TextSymbolizer->alignment.toAscii().data() << "\" --> ignoring!" << endl; |
} |
|
if (TextSymbolizer->dx != 0 || TextSymbolizer->dy != 0) |
ts.set_displacement(TextSymbolizer->dx, TextSymbolizer->dy); |
|
Rule->rl.append(ts); |
} |
} |
else if (qName.toLower() == QString("polygonpatternsymbolizer")) |
{ |
1061,11 → 1173,15 |
return false; |
} |
|
Rule->rl.append(polygon_pattern_symbolizer(findIcon(PolygonPatternSymbolizer->file).toAscii().data(), |
if (PolygonPatternSymbolizer->file.length() <= 0) |
cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Incomplete POLYGONPATTERNSYMBOLIZER --> ignoring!" << endl; |
else |
{ |
Rule->rl.append(polygon_pattern_symbolizer(findIcon(PolygonPatternSymbolizer->file).toAscii().data(), |
getTypeText(PolygonPatternSymbolizer->type), |
PolygonPatternSymbolizer->width, |
PolygonPatternSymbolizer->height)); |
PolygonPatternSymbolizer = PolygonPatternSymbolizer->next; |
} |
} |
else if (qName.toLower() == QString("shieldsymbolizer")) |
{ |
1118,6 → 1234,18 |
Container = in_rule; |
else if (qName.toLower() == QString("rule")) |
Container = in_style; |
else if (qName.toLower() == QString("elsefilter")) |
{ |
Container = in_rule; |
|
if (!Rule) |
{ |
KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of ELSEFILTER outside of a RULE detected!").arg(XmlPath).arg(XmlLine)); |
return false; |
} |
|
Rule->rl.set_else(true); |
} |
else if (qName.toLower() == QString("style")) |
{ |
Container = in_map; |
1147,17 → 1275,17 |
*/ |
bool SRender::characters (const QString& chraw) |
{ |
if (chraw.at(0) == QChar('\n')) |
{ |
XmlLine++; |
return true; |
} |
|
QString ch = chraw.trimmed(); |
|
if (ch.length() == 0) |
return true; |
|
if (ch.at(0) == QChar('\n')) |
{ |
XmlLine++; |
return true; |
} |
|
if (Container == in_rule && Rule) |
{ |
if (Field == FLD_FILTER) |
1165,7 → 1293,7 |
Rule->filter = ch; |
|
if (!Rule->filter.isEmpty()) |
Rule->rl.set_filter(create_filter(Rule->filter.toAscii().data())); |
Rule->rl.set_filter(create_filter(Rule->filter.toLatin1().data(), "latin1")); |
else |
cerr << "Warning in file " << XmlPath.toAscii().data() << " at line " << XmlLine << ": Ignoring empty filter!" << endl; |
} |
1241,16 → 1369,30 |
hv0 += "/"; |
|
hv0 += qf.fileName(); |
qf.setFile (hv0 + ".shp"); |
|
if (__map_type == MAP_SHAPE) |
qf.setFile (hv0 + ".shp"); |
else if (__map_type == MAP_OSM) |
qf.setFile (hv0 + ".osm"); |
|
if (!qf.exists()) |
{ |
KMessageBox::error(0, i18n("The shape file \"%1\" at line %2 does not exist!").arg(hv0+".shp").arg(XmlLine)); |
if (__map_type == MAP_SHAPE) |
KMessageBox::error(0, i18n("The shape file \"%1\" at line %2 does not exist!").arg(hv0+".shp").arg(XmlLine)); |
else if (__map_type == MAP_OSM) |
KMessageBox::error(0, i18n("The OSM file \"%1\" at line %2 does not exist!").arg(hv0+".osm").arg(XmlLine)); |
|
return false; |
} |
|
Lay->Datasource.file = hv0; |
} |
else if (Names == parser__) |
Lay->Datasource.parser = ch; |
else if (Names == url) |
Lay->Datasource.url = ch; |
else if (Names == bbox) |
Lay->Datasource.bbox = ch; |
else if (Names == host) |
Lay->Datasource.host = ch; |
else if (Names == user) |
1379,65 → 1521,91 |
m.setHeight(height); |
// load_map(m, XmlPath.toAscii().data()); |
|
if (!ControlSet) // Initialize the map? |
try |
{ |
QXmlInputSource source (&file); |
reader.setContentHandler (this); |
reader.parse (source); |
} |
if (!ControlSet) // Initialize the map? |
{ |
QXmlInputSource source (&file); |
reader.setContentHandler (this); |
reader.parse (source); |
} |
|
save_map(m, "/home/andreas/.sportwatcher/spw.xml"); |
// save_map(m, "/home/andreas/.sportwatcher/spw1.xml"); |
plx = lx; |
ply = ly; |
prx = rx; |
pry = ry; |
projection pj(m.srs()); |
save_map(m, "/home/andreas/.sportwatcher/spw.xml"); |
// save_map(m, "/home/andreas/.sportwatcher/spw1.xml"); |
plx = lx; |
ply = ly; |
prx = rx; |
pry = ry; |
projection pj(m.srs()); |
|
if (pj.is_geographic()) |
{ |
pj.inverse(plx, ply); |
pj.inverse(prx, pry); |
if (pj.is_geographic()) |
{ |
pj.inverse(plx, ply); |
pj.inverse(prx, pry); |
cout << "Geographic! Inverse projection." << endl; |
} |
else |
{ |
// pj.forward(plx, ply); |
// pj.forward(prx, pry); |
} |
else |
{ |
// pj.forward(plx, ply); |
// pj.forward(prx, pry); |
cout << "NOT geographic!" << endl; |
} |
} |
|
for (unsigned i = 0; i < m.layerCount(); i++) |
{ |
bool vis = m.getLayer(i).isVisible(m.scale_denominator()); |
// bool vis = m.getLayer(i).isVisible(m.scale()); |
cout << "Layer " << i << ": " << m.getLayer(i).name(); |
cout << ", Visible: " << vis; |
cout << ", Active: " << m.getLayer(i).isActive(); |
Envelope <double>e(m.getLayer(i).envelope()); |
cout << ", Extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl; |
} |
|
// First we use Mapnik to create the map |
m.zoomToBox(Envelope<double>(plx, ply, prx, pry)); |
// First we use Mapnik to create the map |
m.zoomToBox(Envelope<double>(plx, ply, prx, pry)); |
|
Envelope <double>e(m.getCurrentExtent()); |
cout << std::setprecision(16) << "Parameter envelope: " << lx << ", " << ly << ", " << rx << ", " << ry << endl; |
cout << std::setprecision(16) << "Converted envelope: " << plx << ", " << ply << ", " << prx << ", " << pry << endl; |
cout << std::setprecision(16) << "Current extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl; |
Envelope <double>x(m.get_buffered_extent()); |
cout << std::setprecision(16) << "Current buf.extent: " << x.minx() << ", " << x.miny() << ", " << x.maxx() << ", " << x.maxy() << endl; |
cout << "SRS: " << m.srs() << endl; |
cout << std::setprecision(16) << "Scale: " << m.scale() << ", scale denominator: " << m.scale_denominator() << endl; |
cout << "width=" << m.getWidth() << ", height=" << m.getHeight() << endl; |
|
Image32 buf(m.getWidth(), m.getHeight()); |
agg_renderer<Image32> ren(m, buf); |
ren.apply(); |
// Put the image into a Qt object |
QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32); |
label->setPixmap(QPixmap::fromImage(image.rgbSwapped())); |
// Create a unique file name |
// pid = getpid(); |
// OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid); |
// save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png"); |
Image32 buf(m.getWidth(), m.getHeight()); |
agg_renderer<Image32> ren(m, buf); |
ren.apply(); |
|
// Put the image into a Qt object |
QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32); |
label->setPixmap(QPixmap::fromImage(image.rgbSwapped())); |
// Create a unique file name |
// pid = getpid(); |
// OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid); |
// save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png"); |
} |
|
catch (const mapnik::config_error &ex) |
{ |
KMessageBox::error(0, i18n("Configuration error: %1").arg(ex.what())); |
return false; |
} |
|
catch (const std::exception &ex) |
{ |
KMessageBox::error(0, i18n("Exception at file %1: %2").arg(XmlPath).arg(ex.what())); |
return false; |
} |
|
catch (...) |
{ |
KMessageBox::error(0, i18n("Unknown exception occured!")); |
return false; |
} |
|
return true; |
} |
|
1641,8 → 1809,11 |
{ |
RULE *Ru = new RULE; |
|
Ru->name.clear(); |
Ru->title.clear(); |
Ru->maxscale = 0; |
Ru->minscale = 0; |
Ru->elsefilter = false; |
Ru->filter.clear(); |
Ru->LineSymbolizer = 0; |
Ru->PolygonSymbolizer = 0; |
1660,12 → 1831,19 |
LAYER *La = new LAYER; |
|
La->name.clear(); // The unique name |
La->title.clear(); |
La->abstract.clear(); |
La->status = false; // Is it active? |
La->clear_label = false; |
La->srs.clear(); // Projection |
La->minzoom = 0.0; |
La->maxzoom = 0.0; |
La->queryable = false; |
La->Datasource.type.clear(); |
La->Datasource.file.clear(); |
La->Datasource.parser.clear(); |
La->Datasource.url.clear(); |
La->Datasource.bbox.clear(); |
La->Datasource.host.clear(); |
La->Datasource.user.clear(); |
La->Datasource.dbname.clear(); |
1744,6 → 1922,8 |
|
ts->name.clear(); |
ts->face_name.clear(); |
ts->placement.clear(); |
ts->alignment.clear(); |
ts->size = 0; |
ts->fill = 0; // Color |
ts->halo_radius = 0; |