39 #pragma warning(disable: 4435 5219 5220)
42 #pragma GCC diagnostic push
43 #pragma GCC diagnostic ignored "-Wpedantic"
45 #include <ogrsf_frmts.h>
47 #pragma GCC diagnostic pop
66 if (!oc.
isSet(
"shapefile-prefixes")) {
70 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
71 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
73 load(*file, oc, toFill, tm);
81 PCLoaderArcView::toShape(OGRLineString* geom,
const std::string& tid) {
84 for (
int j = 0; j < geom->getNumPoints(); j++) {
85 if (fabs(geom->getX(j)) > 180 || fabs(geom->getY(j)) > 90) {
89 if (2 * outOfRange > geom->getNumPoints()) {
90 WRITE_WARNING(
TL(
"No coordinate system found and coordinates look already projected."));
93 WRITE_WARNING(
TL(
"Could not find geo coordinate system, assuming WGS84."));
99 #if GDAL_VERSION_MAJOR < 3
100 for (
int j = 0; j < geom->getNumPoints(); j++) {
101 Position pos(geom->getX(j), geom->getY(j));
103 for (
const OGRPoint& p : *geom) {
107 WRITE_ERRORF(
TL(
"Unable to project coordinates for polygon '%'."), tid);
121 const std::string idField = oc.
getString(
"shapefile.id-column");
122 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
124 std::string shpName = file +
".shp";
126 if (oc.
getString(
"shapefile.fill") ==
"true") {
128 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
131 #if GDAL_VERSION_MAJOR < 2
133 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
136 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
139 throw ProcessError(
TLF(
"Could not open shape description '%'.", shpName));
143 OGRLayer* poLayer = poDS->GetLayer(0);
144 poLayer->ResetReading();
147 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
148 OGRSpatialReference destTransf;
150 destTransf.SetWellKnownGeogCS(
"WGS84");
151 #if GDAL_VERSION_MAJOR > 2
152 if (oc.
getBool(
"shapefile.traditional-axis-mapping") || origTransf !=
nullptr) {
153 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
156 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
157 if (poCT ==
nullptr) {
158 if (oc.
getBool(
"shapefile.guess-projection")) {
159 OGRSpatialReference origTransf2;
160 origTransf2.SetWellKnownGeogCS(
"WGS84");
161 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
167 OGRFeature* poFeature;
168 poLayer->ResetReading();
170 while ((poFeature = poLayer->GetNextFeature()) !=
nullptr) {
171 if (runningID == 0) {
172 std::vector<std::string> fields;
173 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
174 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
178 std::vector<Parameterised*> parCont;
180 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
188 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
192 type += poFeature->GetFieldAsString(typeField.c_str());
196 double layer = oc.
getFloat(
"layer");
215 if (poFeature->GetFieldIndex(
"angle") >= 0) {
216 angle = poFeature->GetFieldAsDouble(
"angle");
219 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
220 if (poGeometry == 0) {
221 OGRFeature::DestroyFeature(poFeature);
225 if (poCT !=
nullptr) {
226 poGeometry->transform(poCT);
228 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
231 OGRPoint* cgeom = (OGRPoint*) poGeometry;
232 Position pos(cgeom->getX(), cgeom->getY());
234 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."),
id);
236 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
237 if (toFill.
add(poi)) {
238 parCont.push_back(poi);
243 case wkbLineString25D: {
244 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
245 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
246 if (toFill.
add(poly)) {
247 parCont.push_back(poly);
252 const bool fill = fillType < 0 || fillType == 1;
253 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
255 if (toFill.
add(poly)) {
256 parCont.push_back(poly);
260 case wkbMultiPoint: {
261 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
262 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
263 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
264 Position pos(cgeom2->getX(), cgeom2->getY());
265 const std::string tid =
id +
"#" +
toString(i);
267 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."), tid);
269 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
270 if (toFill.
add(poi)) {
271 parCont.push_back(poi);
276 case wkbMultiLineString: {
277 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
278 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
279 const std::string tid =
id +
"#" +
toString(i);
280 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
281 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
282 if (toFill.
add(poly)) {
283 parCont.push_back(poly);
288 case wkbMultiPolygon: {
289 const bool fill = fillType < 0 || fillType == 1;
290 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
291 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
292 const std::string tid =
id +
"#" +
toString(i);
293 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
295 if (toFill.
add(poly)) {
296 parCont.push_back(poly);
305 if (oc.
getBool(
"shapefile.add-param")) {
306 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
307 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
308 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
309 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
310 if (poFieldDefn->GetNameRef() != idField) {
311 if (poFieldDefn->GetType() == OFTReal) {
312 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
320 OGRFeature::DestroyFeature(poFeature);
322 #if GDAL_VERSION_MAJOR < 2
323 OGRDataSource::DestroyDataSource(poDS);
#define WRITE_WARNINGF(...)
#define WRITE_ERRORF(...)
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
#define PROGRESS_DONE_MESSAGE()
#define PROGRESS_BEGIN_MESSAGE(msg)
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static methods for processing the coordinates conversion for the current net
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static bool myWarnMissingProjection
static void load(const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Parses pois/polys stored within the given file.
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as shape files-files.
A storage for loaded polygons and pois.
bool add(SUMOPolygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
A storage for type mappings.
const TypeDef & get(const std::string &id)
Returns a type definition.
bool has(const std::string &id)
Returns the information whether the named type is known.
A point in 2D or 3D with translation and scaling methods.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
static RGBColor parseColor(std::string coldef)
Parses a color information.
static const std::string DEFAULT_IMG_FILE
static const double DEFAULT_ANGLE
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
A single definition of values that shall be used for a given type.
std::string icon
the icon to use
bool discard
Information whether polygons of this type shall be discarded.
double layer
The layer to use.
double angle
The angle to use.
std::string imgFile
The image file to use.
std::string id
The new type id to use.
RGBColor color
The color to use.