45 #include <ogrsf_frmts.h>
48 #ifdef CHECK_MEMORY_LEAKS
50 #endif // CHECK_MEMORY_LEAKS
59 if (!oc.
isSet(
"shapefile-prefixes")) {
63 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
64 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
66 load(*file, oc, toFill, tm);
79 std::string prefix = oc.
getString(
"prefix");
82 int layer = oc.
getInt(
"layer");
83 std::string idField = oc.
getString(
"shapefile.id-column");
84 bool useRunningID = oc.
getBool(
"shapefile.use-running-id");
86 std::string shpName = file +
".shp";
88 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
90 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
94 OGRLayer* poLayer = poDS->GetLayer(0);
95 poLayer->ResetReading();
98 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
99 OGRSpatialReference destTransf;
101 destTransf.SetWellKnownGeogCS(
"WGS84");
102 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
104 if (oc.
isSet(
"shapefile.guess-projection")) {
105 OGRSpatialReference origTransf2;
106 origTransf2.SetWellKnownGeogCS(
"WGS84");
107 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
110 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
114 OGRFeature* poFeature;
115 poLayer->ResetReading();
116 unsigned int runningID = 0;
117 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
119 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
123 throw ProcessError(
"Missing id under '" + idField +
"'");
127 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
128 if (poGeometry == 0) {
129 OGRFeature::DestroyFeature(poFeature);
133 poGeometry->transform(poCT);
134 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
137 OGRPoint* cgeom = (OGRPoint*) poGeometry;
140 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
143 if (!toFill.
insert(
id, poi, layer)) {
144 WRITE_ERROR(
"POI '" +
id +
"' could not be added.");
149 case wkbLineString: {
150 OGRLineString* cgeom = (OGRLineString*) poGeometry;
152 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
155 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
160 if (!toFill.
insert(
id, poly, layer)) {
161 WRITE_ERROR(
"Polygon '" +
id +
"' could not be added.");
167 OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
169 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
172 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
177 if (!toFill.
insert(
id, poly, layer)) {
178 WRITE_ERROR(
"Polygon '" +
id +
"' could not be added.");
183 case wkbMultiPoint: {
184 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
185 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
186 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
188 std::string tid =
id +
"#" +
toString(i);
190 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
193 if (!toFill.
insert(tid, poi, layer)) {
194 WRITE_ERROR(
"POI '" + tid +
"' could not be added.");
200 case wkbMultiLineString: {
201 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
202 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
203 OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i);
205 std::string tid =
id +
"#" +
toString(i);
206 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
209 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
214 if (!toFill.
insert(tid, poly, layer)) {
215 WRITE_ERROR(
"Polygon '" + tid +
"' could not be added.");
221 case wkbMultiPolygon: {
222 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
223 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
224 OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing();
226 std::string tid =
id +
"#" +
toString(i);
227 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
230 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
235 if (!toFill.
insert(tid, poly, layer)) {
236 WRITE_ERROR(
"Polygon '" + tid +
"' could not be added.");
243 WRITE_WARNING(
"Unsupported shape type occured (id='" +
id +
"').");
246 OGRFeature::DestroyFeature(poFeature);
250 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
bool insert(const std::string &id, Polygon *poly, int layer, bool ignorePrunning=false)
Adds a polygon to the storage.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
static RGBColor parseColor(std::string coldef)
Parses a color information.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian(Position &from, bool includeInBoundary=true)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
#define WRITE_WARNING(msg)
A storage for loaded polygons and pois.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A storage for type mappings.
static methods for processing the coordinates conversion for the current net
A point in 2D or 3D with translation and scaling methods.
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as shape files-files.
static void load(const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Parses pois/polys stored within the given file.
#define PROGRESS_BEGIN_MESSAGE(msg)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
A storage for options typed value containers)
void push_back_noDoublePos(const Position &p)
static std::string prune(std::string str)
Removes trailing and leading whitechars.
#define PROGRESS_DONE_MESSAGE()
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.