Hi, I'm facing a time problem in my code.
I have 4 tables, this tables has just a few lines (50 - 500) but it has
huge polygons (countries, states, lakes and rivers).
My code executes the same query method over those tables to make an image.
I execute my code on a Windows O.S. machine and it is fast and faster when
dont have anything to return but the same code on a Linux machine is too
slow even when dont have any results to return.
Just to show how it is different, the Windows machine took 20 hours to make
660.000 images, and the Linux one took 60 hours to make the same quantity.

Configuration:
Linux machine: I7 16Gb 1Tb Linux Suse
Windows machine: Core 2 Duo 4 Gb 500Gb Windows 7

Both connect in the same database, it is another linux machine.


public List<Coordinate[]> readCoordinates(String name, ReferencedEnvelope
area){
List<Coordinate[]> contornos = new ArrayList<Coordinate[]>();
SimpleFeatureIterator iterator = null;
try{
//it takes time but I think its normal (0 - 100 ms)
SimpleFeatureSource feature = getDataStore().getFeatureSource(name);

FeatureType schema = feature.getSchema();
String geometryPropertyName = schema.getGeometryDescriptor().getLocalName();

String[] campos = new String[]{geometryPropertyName};

Filter filter = geraFilterBox(area, geometryPropertyName);

Query query = new Query(name, filter);
query.setPropertyNames(campos);

SimpleFeatureCollection fc = feature.getFeatures(query);
//it takes 5 - 400 ms, even when wont return anything
iterator = fc.features();
while (iterator.hasNext()){
//do something but is fast
}
}catch(Exception ioEx){
ioEx.printStackTrace();
} finally {
if (iterator != null) {
//it takes 0 - 300 ms
iterator.close();
}
}
return contornos;
}

private Filter geraFilterBox(ReferencedEnvelope envelope, String
geometryPropertyName) {
FilterFactory2 filterFactory2 =
CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
Filter filter = filterFactory2.bbox(
filterFactory2.property( geometryPropertyName ), envelope );

Filter polygonCheck = filterFactory2.not( filterFactory2.disjoint(
filterFactory2.property(geometryPropertyName),
filterFactory2.literal( generatePolygon(envelope)) ));

filter = filterFactory2.and( filter, polygonCheck );
return filter;
}

private Polygon generatePolygon(ReferencedEnvelope envelope) {

double xMin = envelope.getMinX();
double yMin = envelope.getMinY();
double xMax = envelope.getMaxX();
double yMax = envelope.getMaxY();

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);

Coordinate[] area = {new Coordinate(xMin, yMin),
new Coordinate(xMax, yMin),
new Coordinate(xMax, yMax),
new Coordinate(xMin, yMax),
new Coordinate(xMin, yMin)};

LinearRing geometry = geometryFactory.createLinearRing(area);

Polygon polygon = geometryFactory.createPolygon(geometry, null);

return polygon;
}

private DataStore getDataStore() {
if (dataStore == null) {
try {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(JDBCDataStoreFactory.DBTYPE.key, "postgis");
params.put(JDBCDataStoreFactory.HOST.key, "***.***.*.*");
params.put(JDBCDataStoreFactory.PORT.key, 5432);
params.put(JDBCDataStoreFactory.USER.key, "***");
params.put(JDBCDataStoreFactory.PASSWD.key, "******");
params.put(JDBCDataStoreFactory.DATABASE.key, "******");
params.put(JDBCDataStoreFactory.VALIDATECONN.key, Boolean.TRUE);
dataStore = DataStoreFinder.getDataStore( params );
} catch (IOException e) {
e.printStackTrace();
}
}
return dataStore;
}

Please help me.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to