The contains() method is only implemented for paths.
in
Programming Questions
•
10 months ago
Hi all,
I figured out a way of how to read in an ESRI shape file, and how to convert the features into a PShape:
Now I would like to fill the PShape whenever the mouse is over it. The obvious way (see below) gives me the error message of the topic header.
I found some external libraries (e.g. http://www.ricardmarxer.com/geomerative/ or http://code.google.com/p/gicentre-geomap/) that might help here, but their classes limit my work in other ways. So I would be interested if someone has an idea about how to solve my problem with "standard processing".
Any comments are very welcome!
Thanks in advance,
Benjamin
I figured out a way of how to read in an ESRI shape file, and how to convert the features into a PShape:
- private PShape getPShape(Feature ft) {
PShape featureShape;
GeometryCollection gc = (GeometryCollection) ft.getDefaultGeometry();
PVector[] scrCoords = getScreenCoords(gc);
if(gc instanceof MultiLineString){
featureShape = createShape(LINES);
for(PVector scrCoord : scrCoords){
featureShape.vertex(scrCoord.x, scrCoord.y);
}
featureShape.noFill();
featureShape.stroke(150, 50, 50);
featureShape.strokeWeight(1);
featureShape.end();
} else if(gc instanceof MultiPolygon){
featureShape = createShape();
for(PVector scrCoord : scrCoords){
featureShape.vertex(scrCoord.x, scrCoord.y);
}
featureShape.noFill();
featureShape.stroke(255, 255, 255);
featureShape.strokeWeight(5);
featureShape.end(CLOSE);
} else {
throw new RuntimeException("Unsupported GeometryType: " + gc.getGeometryType());
}
- private PVector[] getScreenCoords(GeometryCollection gc) {
Coordinate[] coords = gc.getCoordinates();
PVector[] scrCoords = new PVector[coords.length];
for(int i=0; i<coords.length; i++){
PVector coord = new PVector((float) coords[i].x, (float) coords[i].y);
PVector scrCoord = geoToScreen(coord);
scrCoords[i] = scrCoord;
}
return scrCoords;
}
Now I would like to fill the PShape whenever the mouse is over it. The obvious way (see below) gives me the error message of the topic header.
- @Override
public void draw(){
shape(munich);
for(PShape childShape : munich.getChildren()){
if(childShape.contains(mouseX, mouseY)){
childShape.fill(255, 255, 255);
}
}
}
I found some external libraries (e.g. http://www.ricardmarxer.com/geomerative/ or http://code.google.com/p/gicentre-geomap/) that might help here, but their classes limit my work in other ways. So I would be interested if someone has an idea about how to solve my problem with "standard processing".
Any comments are very welcome!
Thanks in advance,
Benjamin
1