Commit ea1dd537 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

MRG

parents b91e6399 0f3b94d4
#include "otbVectorDataFileReader.h"
#include "otbVectorData.h"
#include "otbVectorDataProjectionFilter.h"
#include <fstream>
#include <iostream>
#include "itkTreeContainer.h"
#include "itkDataObject.h"
#include "otbDataNode.h"
#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 <mapnik/memory_datasource.hpp>
#include <mapnik/value.hpp>
// ./mapnikFromVectorData ~/OTB/trunk/OTB-Data/Input/ToulouseRoad-examples.shp
typedef otb::VectorData<> VectorDataType;
typedef otb::DataNode<double,2,double> DataNodeType;
typedef DataNodeType::Pointer DataNodePointerType;
typedef itk::TreeContainer<DataNodePointerType> DataTreeType;
typedef VectorDataType::DataTreeType::TreeNodeType InternalTreeNodeType;
typedef InternalTreeNodeType::ChildrenListType ChildrenListType;
typedef boost::shared_ptr<mapnik::memory_datasource> datasource_ptr;
void ProcessNode(InternalTreeNodeType * source, datasource_ptr mDatasource)
{
// Get the children list from the input node
ChildrenListType children = source->GetChildrenList();
// For each child
for(ChildrenListType::iterator it = children.begin(); it!=children.end();++it)
{
// Copy input DataNode info
DataNodePointerType dataNode = (*it)->Get();
switch(dataNode->GetNodeType())
{
case otb::ROOT:
{
ProcessNode((*it),mDatasource);
break;
}
case otb::DOCUMENT:
{
ProcessNode((*it),mDatasource);
break;
}
case otb::FOLDER:
{
ProcessNode((*it),mDatasource);
break;
}
// case FEATURE_POINT:
// {
// newDataNode->SetPoint(this->ReprojectPoint(dataNode->GetPoint()));
// newContainer = OutputInternalTreeNodeType::New();
// newContainer->Set(newDataNode);
// destination->AddChild(newContainer);
// break;
// }
case otb::FEATURE_LINE:
{
std::cout << std::setprecision(15) << " ** Inserting new line **" << std::endl;
typedef mapnik::vertex<double,2> vertex2d;
typedef mapnik::line_string<vertex2d,mapnik::vertex_vector2> line2d;
typedef boost::shared_ptr<line2d> line_ptr;
mapnik::geometry2d * line = new line2d;
typedef DataNodeType::LineType::VertexListConstIteratorType VertexIterator;
VertexIterator itVertex = dataNode->GetLine()->GetVertexList()->Begin();
while (itVertex != dataNode->GetLine()->GetVertexList()->End())
{
std::cout << itVertex.Value()[0] << ", " << itVertex.Value()[1] << std::endl;
line->line_to(itVertex.Value()[0],itVertex.Value()[1]);
++itVertex;
}
std::cout << "Num points: " << line->num_points() << std::endl;
typedef boost::shared_ptr<mapnik::raster> raster_ptr;
typedef mapnik::feature<mapnik::geometry2d,raster_ptr> Feature;
typedef boost::shared_ptr<Feature> feature_ptr;
// typedef std::map<std::string,mapnik::value> mapType;
// mapType myMap;
// myMap["name"] = mapnik::value("test");
// std::cout << myMap.size() << std::endl;
feature_ptr mfeature = feature_ptr(new Feature(1));
// feature_ptr mfeature = feature_ptr(new Feature(myMap));
mfeature->add_geometry(line);
// mfeature->properties().insert(make_pair(std::string("name"),
// std::string("test")));
// boost::put(*mfeature, "name", mapnik::value("test"));
mapnik::transcoder tr("ISO-8859");
boost::put(*mfeature, "name", tr.transcode("test"));
boost::put(*mfeature, "name2", 10);
std::cout << mfeature->props().size() << std::endl;
std::cout << " -> " << (*mfeature)["name"] << std::endl;
std::cout << " -> " << (*mfeature)["name2"] << std::endl;
mDatasource->push(mfeature);
break;
}
// case FEATURE_POLYGON:
// {
// newDataNode->SetPolygonExteriorRing(this->ReprojectPolygon(dataNode->GetPolygonExteriorRing()));
// newDataNode->SetPolygonInteriorRings(this->ReprojectPolygonList(dataNode->GetPolygonInteriorRings()));
// newContainer = OutputInternalTreeNodeType::New();
// newContainer->Set(newDataNode);
// destination->AddChild(newContainer);
// break;
// }
// case FEATURE_MULTIPOINT:
// {
// newContainer = OutputInternalTreeNodeType::New();
// newContainer->Set(newDataNode);
// destination->AddChild(newContainer);
// ProcessNode((*it),newContainer);
// break;
// }
// case FEATURE_MULTILINE:
// {
// newContainer = OutputInternalTreeNodeType::New();
// newContainer->Set(newDataNode);
// destination->AddChild(newContainer);
// ProcessNode((*it),newContainer);
// break;
// }
// case FEATURE_MULTIPOLYGON:
// {
// newContainer = OutputInternalTreeNodeType::New();
// newContainer->Set(newDataNode);
// destination->AddChild(newContainer);
// ProcessNode((*it),newContainer);
// break;
// }
// case FEATURE_COLLECTION:
// {
// newContainer = OutputInternalTreeNodeType::New();
// newContainer->Set(newDataNode);
// destination->AddChild(newContainer);
// ProcessNode((*it),newContainer);
// break;
// }
}
}
}
int main(int argc, char * argv[])
{
typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
reader->SetFileName(argv[1]);
// reader->Update();
typedef otb::VectorDataProjectionFilter<VectorDataType, VectorDataType> ProjectionFilterType;
ProjectionFilterType::Pointer projection = ProjectionFilterType::New();
projection->SetInput(reader->GetOutput());
projection->Update();
// mapnik::datasource_cache::instance()->register_datasources( "/home/christop/opensource/mapnik/plugins/input/shape");
// mapnik::datasource_cache::instance()->register_datasources( "/usr/lib/mapnik/0.5/input");
mapnik::freetype_engine::register_font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
mapnik::Map m(800,600);
// m.set_background(mapnik::color_factory::from_string("cadetblue"));
m.set_background(mapnik::color("#f2efe9"));
{
mapnik::feature_type_style style;
mapnik::rule_type rule;
rule.set_max_scale(250000000000LLU);
rule.set_min_scale(600000);
rule.append(mapnik::line_symbolizer(mapnik::color("#f2efe9")));
// rule.append(mapnik::polygon_symbolizer(mapnik::Color(242,239,233)));
style.add_rule(rule);
m.insert_style("world",style);
}
{
mapnik::feature_type_style style;
mapnik::rule_type rule;
rule.set_max_scale(600000);
rule.append(mapnik::line_symbolizer(mapnik::color("#f2efe9")));
// rule.append(mapnik::polygon_symbolizer(mapnik::Color(242,239,233)));
style.add_rule(rule);
m.insert_style("coast-poly",style);
}
{
mapnik::feature_type_style style;
mapnik::rule_type rule;
rule.set_max_scale(600000);
rule.append(mapnik::line_symbolizer(mapnik::color("#e46d71")));
// rule.append(mapnik::polygon_symbolizer(mapnik::Color(242,239,233)));
style.add_rule(rule);
m.insert_style("coast-poly",style);
}
{
mapnik::feature_type_style style;
mapnik::rule_type rule;
rule.set_max_scale(1000000);
// rule.set_min_scale(500000);
rule.append(mapnik::line_symbolizer(mapnik::color("#809bc0"),8.0));
// TextSymbolizer name="name" face_name="DejaVu Sans Book" size="9" fill="#000" halo_radius="1" placement="line"
// text_symbolizer (std::string const &name, std::string const &face_name, unsigned size, color const &fill)
// text_symbolizer (std::string const &name, unsigned size, color const &fill)
mapnik::text_symbolizer textSymb("name", "DejaVu Sans Book", 9, mapnik::color("#000"));
textSymb.set_label_placement(mapnik::LINE_PLACEMENT);
rule.append(textSymb);
style.add_rule(rule);
m.insert_style("roads",style);
}
// <Filter>[highway] = 'motorway' or [highway] = 'motorway_link'</Filter>
// <MaxScaleDenominator>1000000</MaxScaleDenominator>
// <MinScaleDenominator>500000</MinScaleDenominator>
// <LineSymbolizer>
// <CssParameter name="stroke">#809bc0</CssParameter>
// <CssParameter name="stroke-width">3</CssParameter>
// </LineSymbolizer>
datasource_ptr mDatasource = datasource_ptr(new mapnik::memory_datasource);
InternalTreeNodeType * inputRoot = const_cast<InternalTreeNodeType *>(projection->GetOutput()->GetDataTree()->GetRoot());
ProcessNode(inputRoot,mDatasource);
std::cout << "Datasource size: " << mDatasource->size() << std::endl;
// mapnik::parameters p;
// p["type"]="shape";
// p["file"]="world_borders";
mapnik::Layer lyr("world");
// lyr.set_datasource(mapnik::datasource_cache::instance()->create(p));
lyr.set_datasource(mDatasource);
lyr.add_style("roads");
m.addLayer(lyr);
m.zoomToBox(lyr.envelope());
std::cout << "Envelope: " << lyr.envelope() << std::endl;
mapnik::Image32 buf(m.getWidth(),m.getHeight());
mapnik::agg_renderer<mapnik::Image32> ren(m,buf);
ren.apply();
mapnik::save_to_file<mapnik::ImageData32>(buf.data(),"myOwn.png","png");
return EXIT_SUCCESS;
}
#include "otbVectorDataFileReader.h"
#include "otbImageFileWriter.h"
#include "otbVectorData.h"
#include "otbVectorDataProjectionFilter.h"
#include "otbVectorDataExtractROI.h"
#include <fstream>
#include <iostream>
#include "itkRGBAPixel.h"
#include "otbImage.h"
#include "otbVectorDataToImageFilter.h"
// ./mapnikOTBClasses /home/christop/OTB/trunk/OTB-Data/Input/waterways.shp output.png
// ./mapnikOTBClasses ~/OTB/trunk/OTB-Data/Input/ToulouseRoad-examples.shp output.png
// ./mapnikOTBClasses ~/OTB/trunk/OTB-Data/LargeInput/VECTOR/MidiPyrenees/roads.shp output.png
int main(int argc, char * argv[])
{
//Read the vector data
typedef otb::VectorData<> VectorDataType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
reader->SetFileName(argv[1]);
//Reproject the vector data in the proper projection
typedef otb::VectorDataProjectionFilter<VectorDataType, VectorDataType> ProjectionFilterType;
ProjectionFilterType::Pointer projection = ProjectionFilterType::New();
projection->SetInput(reader->GetOutput());
// projection->Update();
std::string projectionRefWkt ="PROJCS[\"UTM Zone 31, Northern Hemisphere\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",3],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]";
projection->SetOutputProjectionRef(projectionRefWkt);
//Convert the vector data into an image
typedef itk::RGBAPixel< unsigned char > PixelType;
typedef otb::Image<PixelType,2> ImageType;
ImageType::SizeType size;
// size[0] = 1000;
// size[1] = 1000;
size[0] = 500;
size[1] = 500;
ImageType::PointType origin;
// origin[0] = 1.3769;//UL lon
// origin[1] = 43.5455;//UL lat
origin[0] = 374149.980555821;//UL easting
origin[1] = 4829183.99443839;//UL northing
ImageType::SpacingType spacing;
// spacing[0] = 0.00002;
// spacing[1] = -0.00002;
spacing[0] = 0.6;
spacing[1] = -0.6;
typedef otb::RemoteSensingRegion<double> RegionType;
RegionType region;
RegionType::SizeType sizeInUnit;
sizeInUnit[0] = size[0]*spacing[0];
sizeInUnit[1] = size[1]*spacing[1];
region.SetSize(sizeInUnit);
region.SetOrigin(origin);
region.SetRegionProjection(projectionRefWkt);
typedef otb::VectorDataExtractROI<VectorDataType> ExtractROIType;
ExtractROIType::Pointer extractROI = ExtractROIType::New();
extractROI->SetRegion(region);
extractROI->SetInput(reader->GetOutput());
typedef otb::VectorDataToImageFilter<VectorDataType, ImageType> VectorDataToImageFilterType;
VectorDataToImageFilterType::Pointer vectorDataRendering = VectorDataToImageFilterType::New();
vectorDataRendering->SetInput(extractROI->GetOutput());
vectorDataRendering->SetSize(size);
vectorDataRendering->SetOrigin(origin);
vectorDataRendering->SetSpacing(spacing);
//Save the image in a file
typedef otb::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(vectorDataRendering->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
return EXIT_SUCCESS;
}
#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 <iostream>
int main ( int argc , char** argv)
{
}
\ No newline at end of file
// #define BOOST_SPIRIT_THREADSAFE
// #define BOOST_DISABLE_ASSERTS 1
#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 <mapnik/memory_datasource.hpp>
#include <iostream>
int main ( int argc , char** argv)
{
using namespace mapnik;
datasource_cache::instance()->register_datasources( "/home/christop/opensource/mapnik/plugins/input/shape");
freetype_engine::register_font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
Map m(800,600);
m.set_background(color_factory::from_string("cadetblue"));
// {
// feature_type_style style;
// rule_type rule;
// rule.append(polygon_symbolizer(color(250, 190, 183)));
// rule.append(line_symbolizer(color('rgb(50%,50%,50%)'),0.1));
// style.add_rule(rule);
// m.insert_style("world",style);
// }
{
feature_type_style style;
rule_type rule;
rule.set_max_scale(250000000000LLU);
rule.set_min_scale(600000);
rule.append(polygon_symbolizer(color("#f2efe9")));
style.add_rule(rule);
m.insert_style("world",style);
}
{
feature_type_style style;
rule_type rule;
rule.set_max_scale(600000);
rule.append(polygon_symbolizer(color("#f2efe9")));
style.add_rule(rule);
m.insert_style("coast-poly",style);
}
typedef vertex<double,2> vertex2d;
typedef line_string<vertex2d,vertex_vector2> line2d;
typedef boost::shared_ptr<line2d> line_ptr;
geometry2d * line = new line2d;
// vertex2d.x = 0;
// vertex2d.y = 0;
std::cout << line->num_points() << std::endl;
line->line_to(0,0);
line->line_to(45,45);
line->line_to(50,30);
line->line_to(0,-30);
line->line_to(-50,-50);
std::cout << line->num_points() << std::endl;
typedef boost::shared_ptr<raster> raster_ptr;
typedef feature<geometry2d,raster_ptr> Feature;
typedef boost::shared_ptr<Feature> feature_ptr;
feature_ptr mfeature = feature_ptr(new Feature(1));
mfeature->add_geometry(line);
typedef boost::shared_ptr<memory_datasource> datasource_ptr;
datasource_ptr mDatasource = datasource_ptr(new memory_datasource);
mDatasource->push(mfeature);
parameters p;
p["type"]="shape";
p["file"]="world_borders";
Layer lyr("world");
// lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.set_datasource(mDatasource);
lyr.add_style("world");
// lyr.add_style("coast-poly");
m.addLayer(lyr);
m.zoomToBox(lyr.envelope());
Image32 buf(m.getWidth(),m.getHeight());
agg_renderer<Image32> ren(m,buf);
ren.apply();
save_to_file<ImageData32>(buf.data(),"myOwn.png","png");
return EXIT_SUCCESS;
}
\ No newline at end of file
This diff is collapsed.
import xml.parsers.expat
fout= open("osm-style-in-c.c", 'w')
writeNextCharData = 0
currentStyleName = ""
isStroke=0
isStrokeWidth=0
isStrokeOpacity=0
isStrokeLinejoin=0
isStrokeLinecap=0
isStrokeDasharray=0
strokeWidth=""
strokeOpacity=""
strokeColor=""
strokeLinejoin=""
strokeLinecap=""
strokeDasharray=""
# 3 handler functions
def start_element(name, attrs):
print 'Start element:', name, attrs
global writeNextCharData
global currentStyleName
if (name == 'Style'):
currentStyleName = attrs['name']
fout.write("{\nmapnik::feature_type_style style;\n")
if (name == 'Rule'):
fout.write("{\nmapnik::rule_type rule;\n")
if (name == 'Filter'):
fout.write("rule.set_filter(mapnik::create_filter(\"")
writeNextCharData=1
if (name == 'MaxScaleDenominator'):
fout.write("rule.set_max_scale(")
writeNextCharData=1
if (name == 'MinScaleDenominator'):
fout.write("rule.set_min_scale(")
writeNextCharData=1
if (name == 'LineSymbolizer'):
fout.write("{\nmapnik::line_symbolizer geom = mapnik::line_symbolizer();\n")
if (name == 'CssParameter'):
global isStroke
global isStrokeWidth
global isStrokeOpacity
global isStrokeLinejoin
global isStrokeLinecap
global isStrokeDasharray
if (attrs['name'] == 'stroke'):
isStroke=1
if (attrs['name'] == 'stroke-width'):
isStrokeWidth=1
if (attrs['name'] == 'stroke-opacity'):
isStrokeOpacity=1
if (attrs['name'] == 'stroke-linejoin'):
isStrokeLinejoin=1
if (attrs['name'] == 'stroke-linecap'):
isStrokeLinecap=1
if (attrs['name'] == 'stroke-dasharray'):
isStrokeDasharray=1
if (name == 'TextSymbolizer'):
fout.write("mapnik::text_symbolizer textSymb(\""+attrs['name']+"\", \""+attrs['face_name']+"\", "+attrs['size']+", mapnik::color(\""+attrs['fill']+"\"));\n")
if (('placement' in attrs) and (attrs['placement'] == "line")):
fout.write("textSymb.set_label_placement(mapnik::LINE_PLACEMENT);\n")
if ('halo_radius' in attrs):
fout.write("textSymb.set_halo_radius("+attrs['halo_radius']+");\n")
if ('wrap_width' in attrs):
fout.write("textSymb.set_wrap_width ("+attrs['wrap_width']+");\n")
if ('dy' in attrs):#no dx in OSM
fout.write("textSymb.set_displacement(0.0,"+attrs['dy']+");\n")
fout.write("rule.append(textSymb);\n")
def end_element(name):
print 'End element:', name
global writeNextCharData
global strokeColor
global strokeWidth
global strokeOpacity
global strokeLinejoin
global strokeLinecap
global strokeDasharray
global currentStyleName
if (name == 'Style'):
fout.write("mapnikMap.insert_style(\""+currentStyleName+"\",style);\n}\n")
currentStyleName = ""
if (name == 'Rule'):
fout.write("style.add_rule(rule);\n}\n")
if (name == 'Filter'):
fout.write("\"));\n")
writeNextCharData=0
if (name == 'MaxScaleDenominator'):
fout.write("LLU);\n");
writeNextCharData=0
if (name == 'MinScaleDenominator'):
fout.write("LLU);\n");
writeNextCharData=0
if (name == 'LineSymbolizer'):
if (strokeWidth != ""):
fout.write("mapnik::stroke stroke = mapnik::stroke(mapnik::color(\""+strokeColor+"\"), "+strokeWidth+");\n")
else:
fout.write("mapnik::stroke stroke = mapnik::stroke(mapnik::color(\""+strokeColor+"\"));\n")
if (strokeOpacity != ""):
fout.write("stroke.set_opacity ("+strokeOpacity+");\n")
if (strokeLinejoin == "round"):#no other case appears in OSM
fout.write("stroke.set_line_join(mapnik::ROUND_JOIN);\n")
if (strokeLinecap == "round"):#no other case appears in OSM
fout.write("stroke.set_line_cap(mapnik::ROUND_CAP);\n")
if (strokeDasharray != ""):
fout.write("stroke.add_dash("+strokeDasharray+");\n")
fout.write("geom.set_stroke(stroke);\n")
fout.write("rule.append(geom);\n}\n")
strokeWidth, strokeOpacity, strokeColor, strokeLinejoin, strokeLinecap = "", "", "", "", ""
if (name == 'CssParameter'):
global isStroke
global isStrokeWidth
global isStrokeOpacity
global isStrokeLinejoin
global isStrokeLinecap
global isStrokeDasharray
if (isStroke):
isStroke=0
if (isStrokeWidth):
isStrokeWidth=0
if (isStrokeOpacity):
isStrokeOpacity=0
if (isStrokeLinejoin):
isStrokeLinejoin=0