Closed ChrisXuzhou closed 3 years ago
ADD more code of converting from polygon:
` public static S2Polygon makePolygon(String str) {
try {
String poly = parsePolygonFrom(str);
List<S2Loop> loops = Lists.newArrayList();
for (String token : Splitter.on(';').omitEmptyStrings().split(poly)) {
S2Loop loop = makeLoop(token);
loop.normalize();
loops.add(loop);
}
return new S2Polygon(loops);
} catch (Exception e) {
throw new GeometryException(GeometryException.WKT_FORMAT_ERROR, GeometryException.WKT_FORMAT_ERROR, e);
}
}`
` private final static String POLYGON_PREFIX = "POLYGON\(\("; private final static String POLYGON_SUFFIX = "\)\)";
public static String parsePolygonFrom(String origin) {
String p1 = origin.replaceAll(POLYGON_PREFIX, "");
return p1.replaceAll(POLYGON_SUFFIX, "");
}
`
' static S2Loop makeLoop(String str) {
List
@ChrisXuzhou what is the value for MAX_CELLS?
@ChrisXuzhou Hi. I had same problem yesterday.
make sure your loops are normalized.
S2Loop's direction must be CCW
direction. but your polygon isn't.
usenormalize()
to normalize your loops
Had a similar problem. Normalization alone did not help. As I understand, normalize() ensures the correct direction but does not ensure that the loop is a valid polygon. In addition to normalization, ensure that your vertices are listed in the correct order or add an isValid()
check before getting a cover.
Normalization occurs after the covering is generated, so it has no chance of helping.
The PriorityQueue contains relatively small objects, so if you're OOMing it's very likely because of the parameters you're using.
Steve, Chris, can you share more complete examples, in particular showing how you each construct an S2RegionCoverer?
Thanks,
I'm closing this, but feel free to reopen if you have more details to share.
My code like this:
` S2Polygon s2Polygon = makePolygon(polygon);
OOM happened!
analyzed the java.hprof, found the PriorityQueue used 3.5GB memory, which leaded to the out of memory.
the parameter polygon like this: