Я в настоящее время разрабатываю инструмент для отслеживания и прогнозирования пути. Каждый объект в настоящее время обрабатывается потоком. (Спорно, если это правильный подход, но я бы столкнуться с той же проблемой, изменив этот подход).
1002 * У меня есть Singelton myDataStore (мой собственный класс) ведьма держит все данные, необходимые для расчетов (только для чтения ). Данные создаются / настраиваются во время инициализации myDataStore.
Во время отслеживания мне нужно найти ближайшую линию (SimpleFeature) из моей текущей позиции. Для этого я использую SpatialIndexFeatureCollection из geotools, а также с помощью referencedEnvelope и BBox. Это работает нормально и возвращает правильную строку.
Как вы можете себе представить, эта функция вызывается довольно часто (для каждого обновления позиции ojbects). Я читал, что DataStore от Geotools является потокобезопасным. Хранилище данных инициализируется в myDataStore и сохраняется как объект хранилища данных. Затем он передается в функции через
public static synchronized FileDataStore getTaxilineDataStore(){
return taxilineDataStore}
public static SimpleFeatureCollection getClosestLines(Map<String, Object> parameters) throws IOException {
Coordinate pt = getParm(parameters, "Coordinate", null);
TaxilineType type = getParm(parameters, "Type", null);
if (pt != null) {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
SimpleFeatureSource featureSource = DataStoreS.getLineDataStore().getFeatureSource();
SimpleFeatureCollection features;
try {
features = featureSource.getFeatures();
SpatialIndexFeatureCollection index = new SpatialIndexFeatureCollection(features.getSchema());
index.addAll(features);
ReferencedEnvelope search = new ReferencedEnvelope(new Envelope(pt), index.getSchema().getCoordinateReferenceSystem());
search.expandBy(MAX_SEARCH_DISTANCE);
Filter filter = ff.bbox(ff.property(index.getSchema().getGeometryDescriptor().getName()), (BoundingBox) search);
if (type != null) {
filter = ff.and(filter, ff.equal(ff.property("TaxilType"), ff.literal(type.toString()), false));
//filter = ff.equal(ff.property("TaxilType"), ff.literal(type.toString()), false);
}
return index.subCollection(filter);
}
catch (IOException e) {
e.printStackTrace();
return null;
}
} else {
return null;
}
}
. Лучше всего было бы создать индекс один раз и передать его функциям. Поток индекса безопасен? Как я мог справиться с проблемой, когда я не хочу реструктурировать (для целей обучения я вроде как новичок в java). Ошибка выдается
features = featureSource.getFeatures();
Ошибка:
ПРЕДУПРЕЖДЕНИЕ Не удалось открыть файл .shx, продолжая при условии, что файл .shp не редкий java .io.IOException в org.geotools.data.shapefile.shp.IndexFile. (IndexFile. java: 110) в org.geotools.data.shapefile.shp.ShapefileReader. (ShapefileReader. java: 260) в org.geotools.data .shapefile.ShapefileSetManager.openShapeReader (ShapefileSetManager. java: 51) в org.geotools.data.shapefile.ShapefileFeatureSource.readAttributes (ShapefileFeatureSource. *. . java: 475) в org.geotools.data.shapefile.ShapefileFeatureStore.buildFeatureType (ShapefileFeatureStore. java: 134) в org.geotools.data.store.ContentFeatureSource.get *bsoluteSchema: 10) at 28 org.geotools.data.store.ContentFeatureSource.getSchema (ContentFeatureSource. java: 325) в org.geotools.data.store.ContentFeatureCollection. (ContentFeatureCollect ion. java: 80) в org.geotools.data.store.ContentFeatureSource.getFeatures (ContentFeatureSource. java: 583) в org.geotools.data.store.ContentFeatureSource.getFeatures (ContentFeatureSource. java: 114) at [...] getClosestTaxiLines (PathCalculations. java: 95)
Причина: java .nio.channels.ClosedByInterruptException в java .nio.channels.spi.AbstractInterruptibleChannel.end (Неизвестно Источник) по адресу sun.nio.ch.FileChannelImpl.read (Неизвестный источник) по адресу org.geotools.data.shapefile.files.FileChannelDecorator.read (FileChannelDecorator. java: 97) по адресу org.geotools.data.shapefile.shp. IndexFile. (IndexFile. java: 93) ... еще 17