Search in sources :

Example 1 with AdminEntity

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;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) SweepLineOverlapAction(com.vividsolutions.jts.index.sweepline.SweepLineOverlapAction) SweepLineInterval(com.vividsolutions.jts.index.sweepline.SweepLineInterval)

Example 2 with AdminEntity

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>());
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Coordinate(com.vividsolutions.jts.geom.Coordinate) SweepLineInterval(com.vividsolutions.jts.index.sweepline.SweepLineInterval) Point(com.vividsolutions.jts.geom.Point)

Example 3 with 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;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 4 with AdminEntity

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;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity)

Example 5 with AdminEntity

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();
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) NewLocation(org.activityinfo.server.endpoint.rest.model.NewLocation) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) LocationType(org.activityinfo.server.database.hibernate.entity.LocationType) Date(java.util.Date) NewLocation(org.activityinfo.server.endpoint.rest.model.NewLocation) Location(org.activityinfo.server.database.hibernate.entity.Location) Timed(org.activityinfo.server.util.monitoring.Timed)

Aggregations

AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)10 Point (com.vividsolutions.jts.geom.Point)3 LocationType (org.activityinfo.server.database.hibernate.entity.LocationType)3 NewAdminEntity (org.activityinfo.server.endpoint.rest.model.NewAdminEntity)3 Timed (org.activityinfo.server.util.monitoring.Timed)3 Criteria (org.hibernate.Criteria)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 SweepLineInterval (com.vividsolutions.jts.index.sweepline.SweepLineInterval)2 AdminLevel (org.activityinfo.server.database.hibernate.entity.AdminLevel)2 NewAdminLevel (org.activityinfo.server.endpoint.rest.model.NewAdminLevel)2 GeometrySerializer (com.bedatadriven.geojson.GeometrySerializer)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 SweepLineOverlapAction (com.vividsolutions.jts.index.sweepline.SweepLineOverlapAction)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Date (java.util.Date)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 Location (org.activityinfo.server.database.hibernate.entity.Location)1 NewLocation (org.activityinfo.server.endpoint.rest.model.NewLocation)1 JsonFactory (org.codehaus.jackson.JsonFactory)1