-
Notifications
You must be signed in to change notification settings - Fork 80
/
Area.java
139 lines (116 loc) · 3.8 KB
/
Area.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.openstreetmap.atlas.geography.atlas.items;
import java.util.Map;
import java.util.Optional;
import org.openstreetmap.atlas.geography.GeometricSurface;
import org.openstreetmap.atlas.geography.Location;
import org.openstreetmap.atlas.geography.PolyLine;
import org.openstreetmap.atlas.geography.Polygon;
import org.openstreetmap.atlas.geography.Rectangle;
import org.openstreetmap.atlas.geography.atlas.Atlas;
import org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder;
import org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder.LocationIterableProperties;
import org.openstreetmap.atlas.utilities.collections.StringList;
import com.google.gson.JsonObject;
/**
* Area from an {@link Atlas}
*
* @author matthieun
*/
public abstract class Area extends AtlasItem
{
private static final long serialVersionUID = 5244165133018408045L;
protected Area(final Atlas atlas)
{
super(atlas);
}
@Override
public JsonObject asGeoJsonGeometry()
{
return asPolygon().asGeoJsonGeometry();
}
/**
* @return The {@link PolyLine} that represents this {@link LineItem}
*/
public abstract Polygon asPolygon();
@Override
public Rectangle bounds()
{
return asPolygon().bounds();
}
/**
* @return The closed {@link Polygon}, with the end {@link Location} equal to the start
* {@link Location}.
*/
public Polygon getClosedGeometry()
{
return new Polygon(asPolygon().closedLoop());
}
/**
* @return The underlying {@link PolyLine}, which will not have the end {@link Location} equal
* to the start {@link Location}. i.e. the area will not be closed.
*/
@Override
public Iterable<Location> getRawGeometry()
{
return asPolygon();
}
@Override
public ItemType getType()
{
return ItemType.AREA;
}
@Override
public boolean intersects(final GeometricSurface surface)
{
return surface.overlaps(asPolygon());
}
@Override
public String toDiffViewFriendlyString()
{
final String relationsString = this.parentRelationsAsDiffViewFriendlyString();
return "[Area: id=" + this.getIdentifier() + ", polygon=" + this.asPolygon()
+ ", relations=(" + relationsString + "), " + tagString() + "]";
}
@Override
public LocationIterableProperties toGeoJsonBuildingBlock()
{
final Map<String, String> tags = getTags();
tags.put("identifier", String.valueOf(getIdentifier()));
tags.put("osmIdentifier", String.valueOf(getOsmIdentifier()));
tags.put("itemType", String.valueOf(getType()));
final Optional<String> shardName = getAtlas().metaData().getShardName();
shardName.ifPresent(shard -> tags.put("shard", shard));
final StringList parentRelations = new StringList();
this.relations().forEach(relation ->
{
final RelationMember member = relation.members().get(getIdentifier(), getType());
parentRelations.add(member.getRelationIdentifier() + "-" + member.getRole());
});
if (!parentRelations.isEmpty())
{
tags.put("parentRelations", parentRelations.join(", "));
}
return new GeoJsonBuilder.LocationIterableProperties(getClosedGeometry(), tags);
}
@Override
public String toString()
{
return "[Area: id=" + this.getIdentifier() + ", polygon=" + this.asPolygon() + ", "
+ tagString() + "]";
}
@Override
public byte[] toWkb()
{
return this.asPolygon().toWkb();
}
@Override
public String toWkt()
{
return this.asPolygon().toWkt();
}
@Override
public boolean within(final GeometricSurface surface)
{
return this.asPolygon().within(surface);
}
}