127 const std::string idField = oc.
getString(
"shapefile.id-column");
128 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
130 if (oc.
getString(
"shapefile.fill") ==
"true") {
132 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
135#if GDAL_VERSION_MAJOR < 2
137 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);
140 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(file.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
143 throw ProcessError(
TLF(
"Could not open shape description '%'.", file));
147 OGRLayer* poLayer = poDS->GetLayer(0);
148 poLayer->ResetReading();
151#if GDAL_VERSION_MAJOR < 3
152 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
154 const OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
156 OGRSpatialReference destTransf;
158 destTransf.SetWellKnownGeogCS(
"WGS84");
159#if GDAL_VERSION_MAJOR > 2
160 if (oc.
getBool(
"shapefile.traditional-axis-mapping") || origTransf !=
nullptr) {
161 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
164 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
165 if (poCT ==
nullptr) {
166 if (oc.
getBool(
"shapefile.guess-projection")) {
167 OGRSpatialReference origTransf2;
168 origTransf2.SetWellKnownGeogCS(
"WGS84");
169 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
175 OGRFeature* poFeature;
176 poLayer->ResetReading();
178 while ((poFeature = poLayer->GetNextFeature()) !=
nullptr) {
179 if (runningID == 0) {
180 std::vector<std::string> fields;
181 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
182 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
186 std::vector<Parameterised*> parCont;
188 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
196 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
200 type += poFeature->GetFieldAsString(typeField.c_str());
204 double layer = oc.
getFloat(
"layer");
223 if (poFeature->GetFieldIndex(
"angle") >= 0) {
224 angle = poFeature->GetFieldAsDouble(
"angle");
227 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
228 if (poGeometry == 0) {
229 OGRFeature::DestroyFeature(poFeature);
233 if (poCT !=
nullptr) {
234 poGeometry->transform(poCT);
236 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
240 OGRPoint* cgeom = (OGRPoint*) poGeometry;
241 Position pos(cgeom->getX(), cgeom->getY());
243 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."),
id);
245 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
246 if (toFill.
add(poi)) {
247 parCont.push_back(poi);
252 case wkbLineString25D: {
253 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
254 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
255 if (toFill.
add(poly)) {
256 parCont.push_back(poly);
261 case wkbPolygon25D: {
262 const bool fill = fillType < 0 || fillType == 1;
263 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
265 if (toFill.
add(poly)) {
266 parCont.push_back(poly);
271 case wkbMultiPoint25D: {
272 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
273 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
274 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
275 Position pos(cgeom2->getX(), cgeom2->getY());
276 const std::string tid =
id +
"#" +
toString(i);
278 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."), tid);
280 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
281 if (toFill.
add(poi)) {
282 parCont.push_back(poi);
287 case wkbMultiLineString:
288 case wkbMultiLineString25D: {
289 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
290 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
291 const std::string tid =
id +
"#" +
toString(i);
292 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
293 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
294 if (toFill.
add(poly)) {
295 parCont.push_back(poly);
300 case wkbMultiPolygon:
301 case wkbMultiPolygon25D: {
302 const bool fill = fillType < 0 || fillType == 1;
303 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
304 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
305 const std::string tid =
id +
"#" +
toString(i);
306 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
308 if (toFill.
add(poly)) {
309 parCont.push_back(poly);
318 if (oc.
getBool(
"shapefile.add-param") || oc.
getBool(
"all-attributes")) {
319 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
320 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
321 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
322 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
323 if (poFieldDefn->GetNameRef() != idField) {
329 OGRFeature::DestroyFeature(poFeature);
331#if GDAL_VERSION_MAJOR < 2
332 OGRDataSource::DestroyDataSource(poDS);