Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion schema/boundary.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ table Boundary {
osm_id: long;
level: int;
name: string;

code: string;

// Minimum Bounding Rectangle (The "Outer" box)
min_x: double;
min_y: double;
Expand Down
1 change: 1 addition & 0 deletions schema/poi.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ table HierarchyItem {
type:string; // e.g., "country", "state", "city"
name:string; // Localized name
osm_id:long; // Reference to boundary geometry
code:string; // ISO3166-1 if available
}

// POI Geometry (stored as WKB bytes)
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/dedicatedcode/paikka/dto/POIResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,28 @@ public static class HierarchyItem {

@JsonProperty("osm_id")
private long osmId;


@JsonProperty("country_code")
private String code;

@JsonProperty("geometry_url")
private String geometryUrl;

public HierarchyItem() {}

public HierarchyItem(int level, String type, String name, long osmId) {
public HierarchyItem(int level, String type, String name, String code, long osmId) {
this.level = level;
this.type = type;
this.name = name;
this.code = code;
this.osmId = osmId;
}

public HierarchyItem(int level, String type, String name, long osmId, String geometryUrl) {
public HierarchyItem(int level, String type, String name, String code, long osmId, String geometryUrl) {
this.level = level;
this.type = type;
this.name = name;
this.code = code;
this.osmId = osmId;
this.geometryUrl = geometryUrl;
}
Expand All @@ -146,6 +151,9 @@ public HierarchyItem(int level, String type, String name, long osmId, String geo

public String getGeometryUrl() { return geometryUrl; }
public void setGeometryUrl(String geometryUrl) { this.geometryUrl = geometryUrl; }

public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
}

public static class QueryInfo {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dedicatedcode/paikka/flatbuffers/Address.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand Down
62 changes: 26 additions & 36 deletions src/main/java/com/dedicatedcode/paikka/flatbuffers/Boundary.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand All @@ -36,21 +20,25 @@ public final class Boundary extends Table {
public String name() { int o = __offset(8); return o != 0 ? __string(o + bb_pos) : null; }
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(8, 1); }
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 8, 1); }
public double minX() { int o = __offset(10); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double minY() { int o = __offset(12); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double maxX() { int o = __offset(14); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double maxY() { int o = __offset(16); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMinX() { int o = __offset(18); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMinY() { int o = __offset(20); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMaxX() { int o = __offset(22); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMaxY() { int o = __offset(24); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public String code() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; }
public ByteBuffer codeAsByteBuffer() { return __vector_as_bytebuffer(10, 1); }
public ByteBuffer codeInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 10, 1); }
public double minX() { int o = __offset(12); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double minY() { int o = __offset(14); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double maxX() { int o = __offset(16); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double maxY() { int o = __offset(18); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMinX() { int o = __offset(20); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMinY() { int o = __offset(22); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMaxX() { int o = __offset(24); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public double mirMaxY() { int o = __offset(26); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
public com.dedicatedcode.paikka.flatbuffers.Geometry geometry() { return geometry(new com.dedicatedcode.paikka.flatbuffers.Geometry()); }
public com.dedicatedcode.paikka.flatbuffers.Geometry geometry(com.dedicatedcode.paikka.flatbuffers.Geometry obj) { int o = __offset(26); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
public com.dedicatedcode.paikka.flatbuffers.Geometry geometry(com.dedicatedcode.paikka.flatbuffers.Geometry obj) { int o = __offset(28); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }

public static int createBoundary(FlatBufferBuilder builder,
long osmId,
int level,
int nameOffset,
int codeOffset,
double minX,
double minY,
double maxX,
Expand All @@ -60,7 +48,7 @@ public static int createBoundary(FlatBufferBuilder builder,
double mirMaxX,
double mirMaxY,
int geometryOffset) {
builder.startTable(12);
builder.startTable(13);
Boundary.addMirMaxY(builder, mirMaxY);
Boundary.addMirMaxX(builder, mirMaxX);
Boundary.addMirMinY(builder, mirMinY);
Expand All @@ -71,24 +59,26 @@ public static int createBoundary(FlatBufferBuilder builder,
Boundary.addMinX(builder, minX);
Boundary.addOsmId(builder, osmId);
Boundary.addGeometry(builder, geometryOffset);
Boundary.addCode(builder, codeOffset);
Boundary.addName(builder, nameOffset);
Boundary.addLevel(builder, level);
return Boundary.endBoundary(builder);
}

public static void startBoundary(FlatBufferBuilder builder) { builder.startTable(12); }
public static void startBoundary(FlatBufferBuilder builder) { builder.startTable(13); }
public static void addOsmId(FlatBufferBuilder builder, long osmId) { builder.addLong(0, osmId, 0L); }
public static void addLevel(FlatBufferBuilder builder, int level) { builder.addInt(1, level, 0); }
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(2, nameOffset, 0); }
public static void addMinX(FlatBufferBuilder builder, double minX) { builder.addDouble(3, minX, 0.0); }
public static void addMinY(FlatBufferBuilder builder, double minY) { builder.addDouble(4, minY, 0.0); }
public static void addMaxX(FlatBufferBuilder builder, double maxX) { builder.addDouble(5, maxX, 0.0); }
public static void addMaxY(FlatBufferBuilder builder, double maxY) { builder.addDouble(6, maxY, 0.0); }
public static void addMirMinX(FlatBufferBuilder builder, double mirMinX) { builder.addDouble(7, mirMinX, 0.0); }
public static void addMirMinY(FlatBufferBuilder builder, double mirMinY) { builder.addDouble(8, mirMinY, 0.0); }
public static void addMirMaxX(FlatBufferBuilder builder, double mirMaxX) { builder.addDouble(9, mirMaxX, 0.0); }
public static void addMirMaxY(FlatBufferBuilder builder, double mirMaxY) { builder.addDouble(10, mirMaxY, 0.0); }
public static void addGeometry(FlatBufferBuilder builder, int geometryOffset) { builder.addOffset(11, geometryOffset, 0); }
public static void addCode(FlatBufferBuilder builder, int codeOffset) { builder.addOffset(3, codeOffset, 0); }
public static void addMinX(FlatBufferBuilder builder, double minX) { builder.addDouble(4, minX, 0.0); }
public static void addMinY(FlatBufferBuilder builder, double minY) { builder.addDouble(5, minY, 0.0); }
public static void addMaxX(FlatBufferBuilder builder, double maxX) { builder.addDouble(6, maxX, 0.0); }
public static void addMaxY(FlatBufferBuilder builder, double maxY) { builder.addDouble(7, maxY, 0.0); }
public static void addMirMinX(FlatBufferBuilder builder, double mirMinX) { builder.addDouble(8, mirMinX, 0.0); }
public static void addMirMinY(FlatBufferBuilder builder, double mirMinY) { builder.addDouble(9, mirMinY, 0.0); }
public static void addMirMaxX(FlatBufferBuilder builder, double mirMaxX) { builder.addDouble(10, mirMaxX, 0.0); }
public static void addMirMaxY(FlatBufferBuilder builder, double mirMaxY) { builder.addDouble(11, mirMaxY, 0.0); }
public static void addGeometry(FlatBufferBuilder builder, int geometryOffset) { builder.addOffset(12, geometryOffset, 0); }
public static int endBoundary(FlatBufferBuilder builder) {
int o = builder.endTable();
return o;
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dedicatedcode/paikka/flatbuffers/Geometry.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand All @@ -39,25 +23,31 @@ public final class HierarchyItem extends Table {
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(8, 1); }
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 8, 1); }
public long osmId() { int o = __offset(10); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
public String code() { int o = __offset(12); return o != 0 ? __string(o + bb_pos) : null; }
public ByteBuffer codeAsByteBuffer() { return __vector_as_bytebuffer(12, 1); }
public ByteBuffer codeInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 12, 1); }

public static int createHierarchyItem(FlatBufferBuilder builder,
int level,
int typeOffset,
int nameOffset,
long osmId) {
builder.startTable(4);
long osmId,
int codeOffset) {
builder.startTable(5);
HierarchyItem.addOsmId(builder, osmId);
HierarchyItem.addCode(builder, codeOffset);
HierarchyItem.addName(builder, nameOffset);
HierarchyItem.addType(builder, typeOffset);
HierarchyItem.addLevel(builder, level);
return HierarchyItem.endHierarchyItem(builder);
}

public static void startHierarchyItem(FlatBufferBuilder builder) { builder.startTable(4); }
public static void startHierarchyItem(FlatBufferBuilder builder) { builder.startTable(5); }
public static void addLevel(FlatBufferBuilder builder, int level) { builder.addInt(0, level, 0); }
public static void addType(FlatBufferBuilder builder, int typeOffset) { builder.addOffset(1, typeOffset, 0); }
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(2, nameOffset, 0); }
public static void addOsmId(FlatBufferBuilder builder, long osmId) { builder.addLong(3, osmId, 0L); }
public static void addCode(FlatBufferBuilder builder, int codeOffset) { builder.addOffset(4, codeOffset, 0); }
public static int endHierarchyItem(FlatBufferBuilder builder) {
int o = builder.endTable();
return o;
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dedicatedcode/paikka/flatbuffers/Name.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dedicatedcode/paikka/flatbuffers/POI.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dedicatedcode/paikka/flatbuffers/POIList.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* This file is part of paikka.
*
* Paikka is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 or
* any later version.
*
* Paikka is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Paikka. If not, see <https://www.gnu.org/licenses/>.
*/

// automatically generated by the FlatBuffers compiler, do not modify

package com.dedicatedcode.paikka.flatbuffers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private List<POIData> loadPOIsFromShard(long shardId) throws RocksDBException {
item.level(),
itemType != null ? itemType : "unknown",
itemName != null ? itemName : "Unknown",
item.code(),
item.osmId()
));
logger.debug("Copied hierarchy: level={}, type={}, name={}",
Expand Down Expand Up @@ -388,11 +389,11 @@ private POIResponse convertPOIToResponse(POIData poi, double queryLat, double qu
logger.debug("POI {} has {} hierarchy items", poi.id(), poi.hierarchy().size());

for (HierarchyData item : poi.hierarchy()) {
logger.debug("Hierarchy: level={}, type={}, name={}, osmId={}",
item.level(), item.type(), item.name(), item.osmId());
logger.debug("Hierarchy: level={}, type={}, name={}, osmId={}, code={}",
item.level(), item.type(), item.name(), item.osmId(), item.code());

String geometryUrl = buildGeometryUrl(item.osmId());
hierarchy.add(new POIResponse.HierarchyItem(item.level(), item.type(), item.name(), item.osmId(), geometryUrl));
hierarchy.add(new POIResponse.HierarchyItem(item.level(), item.type(), item.name(), item.code(), item.osmId(), geometryUrl));
}
response.setHierarchy(hierarchy);

Expand Down Expand Up @@ -428,7 +429,7 @@ private record POIData(long id, float lat, float lon, String type, String subtyp
private record AddressData(String street, String houseNumber, String postcode, String city, String country) {
}

private record HierarchyData(int level, String type, String name, long osmId) {
private record HierarchyData(int level, String type, String name, String code, long osmId) {
}

private record POIWithDistance(POIData poi, double distance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private List<SimpleHierarchyItem> refresh(double lon, double lat, long cellId) {

return lastActiveBoundaries.stream()
.sorted(Comparator.comparingInt(b -> b.level))
.map(cb -> new SimpleHierarchyItem(cb.level, "administrative", cb.name, cb.osmId))
.map(cb -> new SimpleHierarchyItem(cb.level, "administrative", cb.name, cb.osmId, cb.code))
.toList();
}

Expand All @@ -107,7 +107,7 @@ private CachedBoundary fetchFromDb(long id) {
wkbBuf.get(wkb);

IndexedPointInAreaLocator locator = new IndexedPointInAreaLocator(wkbReader.read(wkb));
return new CachedBoundary(b.level(), b.name(), b.osmId(), mir, mbr, locator);
return new CachedBoundary(b.level(), b.name(), b.code(), b.osmId(), mir, mbr, locator);
} catch (Exception e) { return null; }
}

Expand All @@ -118,7 +118,7 @@ private long[] fetchGridCandidates(long cellId) {
} catch (Exception e) { return null; }
}

public record CachedBoundary(int level, String name, long osmId, Envelope mir, Envelope mbr,
public record CachedBoundary(int level, String name, String code, long osmId, Envelope mir, Envelope mbr,
IndexedPointInAreaLocator locator) {
public boolean contains(double lon, double lat) {
if (mir != null && mir.contains(lon, lat)) return true;
Expand All @@ -127,5 +127,5 @@ public boolean contains(double lon, double lat) {
}
}

public record SimpleHierarchyItem(int level, String type, String name, long osmId) {}
public record SimpleHierarchyItem(int level, String type, String name, long osmId, String code) {}
}
Loading
Loading