126 const std::string idField = oc.
getString(
"shapefile.id-column");
127 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
129 if (oc.
getString(
"shapefile.fill") ==
"true") {
131 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
134#if GDAL_VERSION_MAJOR < 2
136 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);
139 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(file.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
142 throw ProcessError(
TLF(
"Could not open shape description '%'.", file));
146 OGRLayer* poLayer = poDS->GetLayer(0);
147 poLayer->ResetReading();
150 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
151 OGRSpatialReference destTransf;
153 destTransf.SetWellKnownGeogCS(
"WGS84");
154#if GDAL_VERSION_MAJOR > 2
155 if (oc.
getBool(
"shapefile.traditional-axis-mapping") || origTransf !=
nullptr) {
156 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
159 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
160 if (poCT ==
nullptr) {
161 if (oc.
getBool(
"shapefile.guess-projection")) {
162 OGRSpatialReference origTransf2;
163 origTransf2.SetWellKnownGeogCS(
"WGS84");
164 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
170 OGRFeature* poFeature;
171 poLayer->ResetReading();
173 while ((poFeature = poLayer->GetNextFeature()) !=
nullptr) {
174 if (runningID == 0) {
175 std::vector<std::string> fields;
176 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
177 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
181 std::vector<Parameterised*> parCont;
183 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
191 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
195 type += poFeature->GetFieldAsString(typeField.c_str());
199 double layer = oc.
getFloat(
"layer");
218 if (poFeature->GetFieldIndex(
"angle") >= 0) {
219 angle = poFeature->GetFieldAsDouble(
"angle");
222 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
223 if (poGeometry == 0) {
224 OGRFeature::DestroyFeature(poFeature);
228 if (poCT !=
nullptr) {
229 poGeometry->transform(poCT);
231 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
235 OGRPoint* cgeom = (OGRPoint*) poGeometry;
236 Position pos(cgeom->getX(), cgeom->getY());
238 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."),
id);
240 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
241 if (toFill.
add(poi)) {
242 parCont.push_back(poi);
247 case wkbLineString25D: {
248 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
249 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
250 if (toFill.
add(poly)) {
251 parCont.push_back(poly);
256 case wkbPolygon25D: {
257 const bool fill = fillType < 0 || fillType == 1;
258 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
260 if (toFill.
add(poly)) {
261 parCont.push_back(poly);
266 case wkbMultiPoint25D: {
267 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
268 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
269 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
270 Position pos(cgeom2->getX(), cgeom2->getY());
271 const std::string tid =
id +
"#" +
toString(i);
273 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."), tid);
275 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
276 if (toFill.
add(poi)) {
277 parCont.push_back(poi);
282 case wkbMultiLineString:
283 case wkbMultiLineString25D: {
284 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
285 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
286 const std::string tid =
id +
"#" +
toString(i);
287 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
288 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
289 if (toFill.
add(poly)) {
290 parCont.push_back(poly);
295 case wkbMultiPolygon:
296 case wkbMultiPolygon25D: {
297 const bool fill = fillType < 0 || fillType == 1;
298 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
299 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
300 const std::string tid =
id +
"#" +
toString(i);
301 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
303 if (toFill.
add(poly)) {
304 parCont.push_back(poly);
313 if (oc.
getBool(
"shapefile.add-param") || oc.
getBool(
"all-attributes")) {
314 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
315 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
316 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
317 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
318 if (poFieldDefn->GetNameRef() != idField) {
324 OGRFeature::DestroyFeature(poFeature);
326#if GDAL_VERSION_MAJOR < 2
327 OGRDataSource::DestroyDataSource(poDS);