use of org.activityinfo.server.database.hibernate.entity.AdminEntity in project activityinfo by bedatadriven.
the class BatchGeocoder method geocode.
public List<List<AdminEntity>> geocode() {
entities = queryEntities();
// add the entities to the sweep line index
indexEntities();
index.computeOverlaps(new SweepLineOverlapAction() {
@Override
public void overlap(SweepLineInterval s0, SweepLineInterval s1) {
// is this an overlap between a point and and entity?
if (s0.getItem() instanceof Integer && s1.getItem() instanceof AdminEntity) {
checkContains((Integer) s0.getItem(), (AdminEntity) s1.getItem());
} else if (s1.getItem() instanceof Integer && s0.getItem() instanceof AdminEntity) {
checkContains((Integer) s1.getItem(), (AdminEntity) s0.getItem());
}
}
});
return results;
}
use of org.activityinfo.server.database.hibernate.entity.AdminEntity in project activityinfo by bedatadriven.
the class BatchGeocoder method addPoint.
public void addPoint(double x, double y) {
int pointIndex = points.size();
// add the point to the list
points.add(gf.createPoint(new Coordinate(x, y)));
// index the point
index.add(new SweepLineInterval(x, x, pointIndex));
// add an empty result
results.add(new ArrayList<AdminEntity>());
}
use of org.activityinfo.server.database.hibernate.entity.AdminEntity in project activityinfo by bedatadriven.
the class Geocoder method geocode.
/**
* Geocode a single point to a list of admin entities
*
* @param latitude
* @param longitude
* @return
*/
public List<AdminEntity> geocode(double latitude, double longitude) {
Point point = gf.createPoint(new Coordinate(longitude, latitude));
Session session = sessionProvider.get();
Criteria criteria = session.createCriteria(AdminEntity.class);
criteria.add(SpatialRestrictions.contains("geometry", point));
// mysql seems to check only the MBRs. We need to verify
// that the point is actually contained by the geometry
List<AdminEntity> containedByMbr = criteria.list();
List<AdminEntity> contains = Lists.newArrayList();
for (AdminEntity entity : containedByMbr) {
if (JtsUtil.contains(entity.getGeometry(), point)) {
contains.add(entity);
}
}
return contains;
}
use of org.activityinfo.server.database.hibernate.entity.AdminEntity in project activityinfo by bedatadriven.
the class MysqlGeometryProvider method getGeometries.
@Override
public List<AdminGeo> getGeometries(int adminLevelId) {
List<AdminEntity> entityList = em.get().createQuery("select e from AdminEntity e where e.level.id = :levelId and e" + ".deleted = false and e.geometry is not null").setParameter("levelId", adminLevelId).getResultList();
List<AdminGeo> resultList = Lists.newArrayList();
for (AdminEntity entity : entityList) {
resultList.add(new AdminGeo(entity.getId(), entity.getGeometry()));
}
return resultList;
}
use of org.activityinfo.server.database.hibernate.entity.AdminEntity in project activityinfo by bedatadriven.
the class LocationsResource method postNewLocations.
@POST
@Path("/{typeId}")
@Timed(name = "api.rest.locations.post")
public Response postNewLocations(@InjectParam EntityManager entityManager, @PathParam("typeId") int locationTypeId, List<NewLocation> locations) {
KeyGenerator generator = new KeyGenerator();
entityManager.getTransaction().begin();
LocationType locationType = entityManager.getReference(LocationType.class, locationTypeId);
for (NewLocation newLocation : locations) {
Location location = new Location();
location.setId(generator.generateInt());
System.out.println(location.getId());
location.setName(newLocation.getName());
location.setLocationType(locationType);
location.setX(newLocation.getLongitude());
location.setY(newLocation.getLatitude());
location.setTimeEdited(new Date());
location.setAdminEntities(new HashSet<AdminEntity>());
for (int entityId : newLocation.getAdminEntityIds()) {
location.getAdminEntities().add(entityManager.getReference(AdminEntity.class, entityId));
}
entityManager.persist(location);
}
entityManager.getTransaction().commit();
return Response.ok().build();
}
Aggregations