Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Osm tags #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/io/sharedstreets/data/SharedStreetsOSMMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public class WaySectionMetadata implements Serializable {
public Long[] nodeIds;
public String name;

public String[] tagNames;
public String[] tagValues;

public WaySectionMetadata( WaySection section, boolean storeWaySegmentNames) {

this.wayId = section.wayId;

this.roadClass = section.roadClass;
Expand All @@ -42,6 +46,17 @@ public WaySectionMetadata( WaySection section, boolean storeWaySegmentNames) {
for(int i = 0; i < section.nodes.length; i++) {
this.nodeIds[i] = section.nodes[i].nodeId;
}

this.tagNames = new String[section.fields.keySet().size()];
this.tagValues = new String[section.fields.keySet().size()];

int i = 0;
for(String key : section.fields.keySet()) {
this.tagNames[i] = key;
this.tagValues[i] = section.fields.get(key);
i++;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As adding osm tags will have a substantial consequence on size of the generated tiles, could you elaborate a bit on the reasons why these are added? Perhaps this should be optional? Or at least the keys be filterable?

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public static UniqueId generateId(SharedStreetsReference ssr) {
}
}
UniqueId id = UniqueId.generateHash(hashString);

return id;
}

Expand Down
43 changes: 39 additions & 4 deletions src/main/java/io/sharedstreets/tools/builder/ProcessPBF.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ public static void main(String[] args) throws Exception {
.withArgName("Z-LEVEL")
.create() );

options.addOption( OptionBuilder.withLongOpt( "roadClass" )
.withDescription( "road class (default 6)" )
.hasArg()
.withArgName("Z-LEVEL")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Z-LEVEL seems to be a copy paste error

.create() );


String inputFile = "";

String outputPath = "";

Integer zLevel = 12 ;

Integer roadClass = 6 ;

try {
// parse the command line arguments
CommandLine line = parser.parse( options, args );
Expand All @@ -82,6 +90,10 @@ public static void main(String[] args) throws Exception {
if(line.hasOption("zlevel")){
zLevel = Integer.parseInt(line.getOptionValue("zlevel"));
}

if(line.hasOption("roadClass")){
roadClass = Integer.parseInt(line.getOptionValue("roadClass"));
}
Comment on lines +94 to +96
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should really only one roadClass be processed or multiple? In #25, I assumed that multiple road classes should be processed?

}
catch( Exception exp ) {
System.out.println( "Unexpected exception:" + exp.getMessage() );
Expand Down Expand Up @@ -113,10 +125,33 @@ public static void main(String[] args) throws Exception {

// list of way classes for export tiles (must be in sequential order from least to most filtered)
ArrayList<Way.ROAD_CLASS> filteredClasses = new ArrayList<>();
filteredClasses.add(Way.ROAD_CLASS.ClassUnclassified);
filteredClasses.add(Way.ROAD_CLASS.ClassTertiary);
filteredClasses.add(Way.ROAD_CLASS.ClassPrimary);
filteredClasses.add(Way.ROAD_CLASS.ClassMotorway);

if(roadClass.intValue() == Way.ROAD_CLASS.ClassUnclassified.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassUnclassified);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassTertiary.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassTertiary);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassSecondary.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassSecondary);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassPrimary.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassPrimary);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassTrunk.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassTrunk);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassMotorway.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassUnclassified);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a typo? Shouldn't Way.ROAD_CLASS.ClassMotorway be added?


else if(roadClass.intValue() == Way.ROAD_CLASS.ClassResidential.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassResidential);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassService.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassService);

else if(roadClass.intValue() == Way.ROAD_CLASS.ClassOther.getValue())
filteredClasses.add(Way.ROAD_CLASS.ClassOther);
Comment on lines +128 to +154
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is repetitive and should be handled more compactly.


for(Way.ROAD_CLASS filteredClass : filteredClasses) {

Expand Down
117 changes: 85 additions & 32 deletions src/main/java/io/sharedstreets/tools/builder/osm/model/Way.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,47 +50,100 @@ public boolean isLink() {

}

public String getName() {
public boolean isDrivable() {

if(fields.containsKey("name"))
return fields.get("name").trim();
if(this.isHighway()) {
if((fields.containsKey("motorcar'") && fields.get("motorcar").toLowerCase().equals("no") || fields.get("motorcar").toLowerCase().equals("false")) ||
(fields.containsKey("motor_vehicle") && fields.get("motor_vehicle").toLowerCase().equals("no") || fields.get("motor_vehicle").toLowerCase().equals("false")) ||
(fields.containsKey("vehicle") && fields.get("vehicle").toLowerCase().equals("no") || fields.get("vehicle").toLowerCase().equals("false")) ||
(fields.containsKey("access") && fields.get("motorcar").toLowerCase().equals("no") || fields.get("motorcar").toLowerCase().equals("false"))){
return false;
}

return true;
}
else
return "";
return false;

}

public ROAD_CLASS roadClass() {
public boolean isBikeable() {

if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("motorway"))
return ROAD_CLASS.ClassMotorway;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("trunk"))
return ROAD_CLASS.ClassTrunk;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("primary"))
return ROAD_CLASS.ClassPrimary;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("secondary"))
return ROAD_CLASS.ClassSecondary;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("tertiary"))
return ROAD_CLASS.ClassTertiary;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("unclassified"))
return ROAD_CLASS.ClassUnclassified;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("residential"))
return ROAD_CLASS.ClassResidential;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("service")) {

// attempt to exclude parking lots, driveways and other private driveways to keep just public services roads
// not consistently mapped in OSM... https://taginfo.openstreetmap.org/keys/?key=service#values
if (fields.containsKey("service") && (fields.get("service").toLowerCase().trim().startsWith("parking") ||
fields.get("service").toLowerCase().trim().startsWith("driveway") ||
fields.get("service").toLowerCase().trim().startsWith("drive-through")))
return ROAD_CLASS.ClassOther;
if (fields == null)
return false;

assert fields != null;

return fields.containsKey("bikable");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missing something, but where comes the bikable field from?


}

public boolean isWalkable() {

if (fields == null)
return false;

assert fields != null;

return fields.containsKey("highway");

}

public String getName() {

String name = "";

if(fields.containsKey("name"))
name = fields.get("name").trim();

if(fields.containsKey("ref")) {
if(name.isEmpty())
name = fields.get("ref").trim();
else
return ROAD_CLASS.ClassService;
name += "; " + fields.get("ref").trim();
}

return name;
}

public ROAD_CLASS roadClass() {


if(fields.containsKey("highway")) {
if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("motorway"))
return ROAD_CLASS.ClassMotorway;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("trunk"))
return ROAD_CLASS.ClassTrunk;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("primary"))
return ROAD_CLASS.ClassPrimary;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("secondary"))
return ROAD_CLASS.ClassSecondary;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("tertiary"))
return ROAD_CLASS.ClassTertiary;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("unclassified"))
return ROAD_CLASS.ClassUnclassified;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("residential"))
return ROAD_CLASS.ClassResidential;
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("service")) {

// attempt to exclude parking lots, driveways and other private driveways to keep just public services roads
// not consistently mapped in OSM... https://taginfo.openstreetmap.org/keys/?key=service#values
if (fields.containsKey("service") && (fields.get("service").toLowerCase().trim().startsWith("parking") ||
fields.get("service").toLowerCase().trim().startsWith("driveway") ||
fields.get("service").toLowerCase().trim().startsWith("drive-through")))
return ROAD_CLASS.ClassOther;
else
return ROAD_CLASS.ClassService;


} else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("living_street"))
return ROAD_CLASS.ClassResidential;
else
return ROAD_CLASS.ClassOther;
}
else {
return ROAD_CLASS.ClassOther; // fall back to "other" for unknown
}
else if (fields.containsKey("highway") && fields.get("highway").toLowerCase().trim().startsWith("living_street"))
return ROAD_CLASS.ClassResidential;
else
return ROAD_CLASS.ClassOther;
}

public boolean isRoundabout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public DataSet<Tuple2<TileId, TilableData>> getTiledReferences(int zLevel)
@Override
public void flatMap(SharedStreetsReference value, Collector<Tuple2<TileId, TilableData>> out) throws Exception {
Set<TileId> tileIds = value.getTileKeys(zLevel);

for(TileId id : tileIds) {
out.collect(new Tuple2<TileId, TilableData>(id, value));
}
Expand Down