Ejemplo n.º 1
0
 def get_latlon(self):
     geo = IGeoManager(self.context)
     geom = geo.getCoordinates()
     if geom:
         if geom[0] == 'Point':
             return '<geo:Point geo:lat="%f" geo:long="%f"/>' % (
                 geom[1][1], geom[1][0])
Ejemplo n.º 2
0
    def get_venues(self):
        """This function retrieves all related Venue objects for given Info
        and for each Venue gets the coordinates.

        Return a list of venues which have coordinates set.

        Each element of this list is a dictionary that contains three keys:
        location, title, description
        """
        venues = []
        refs = self.context.venue
        if not refs:
            return venues

        for ref in refs:
            ob = ref.to_object
            geo = IGeoManager(ob, None)
            if geo and geo.isGeoreferenceable():
                geometry, coordinates = geo.getCoordinates()
                if not coordinates or len(coordinates) != 2:
                    continue
                else:
                    longitude, latitude = coordinates
                if geometry == 'Point' and longitude and latitude:
                    venues.append({
                        'title':
                        ob.Title(),
                        'description':
                        DESC_TEMPLATE % ob.Description(),
                        'location':
                        "%r,%r,0.000000" % (longitude, latitude),
                    })

        return venues
Ejemplo n.º 3
0
    def get_venues(self):
        """This function retrieves all related Venue objects for given Info
        and for each Venue gets the coordinates.

        Return a list of venues which have coordinates set.

        Each element of this list is a dictionary that contains three keys:
        location, title, description
        """
        venues = []
        refs = self.context.venue
        if not refs:
            return venues

        for ref in refs:
            ob = ref.to_object
            geo = IGeoManager(ob, None)
            if geo and geo.isGeoreferenceable():
                geometry, coordinates = geo.getCoordinates()
                if not coordinates or len(coordinates) != 2:
                    continue
                else:
                    longitude, latitude = coordinates
                if geometry == 'Point' and longitude and latitude:
                    venues.append({
                        'title': ob.Title(),
                        'description': DESC_TEMPLATE % ob.Description(),
                        'location': "%r,%r,0.000000" % (longitude, latitude),
                    })

        return venues
Ejemplo n.º 4
0
def is_georeferenced(context):
    try:
        geo = IGeoManager(context)
        if geo.isGeoreferenceable():
            if geo.getCoordinates()[0]:
                return True
    except TypeError:
        # catch TypeError: ('Could not adapt', <ATFile ...>, <Interfa...oManager>)
        pass
    return False
Ejemplo n.º 5
0
 def layers(self):
     #add basemaps
     layers = super(LegalFWMapLayers, self).layers()
     geo = IGeoManager(self.context)
     if self.context.getField('country').get(self.context):
         layers.append(LegalFWCountryMapLayer(self.context))
     if self.context.getField('basin').get(self.context):
         layers.append(LegalFWBasinMapLayer(self.context))
     if geo.isGeoreferenceable():
         if geo.getCoordinates():
             layers.append(LegalFWMapLayer(self.context))
     return layers
Ejemplo n.º 6
0
    def _get_markers(self, brain):
        """Return dict of marker details.

        Handle Info objects in special way.
        """
        markers = []
        if brain.portal_type == 'tbfac.Info':
            # get related Venues
            obj = brain.getObject()
            if obj is None:
                return []

            refs = obj.venue
            if not refs:
                return []

            for ref in refs:
                venue = ref.to_object
                geo = IGeoManager(venue, None)
                if geo and geo.isGeoreferenceable():
                    geometry, coordinates = geo.getCoordinates()
                    if not coordinates or len(coordinates) != 2:
                        continue
                    else:
                        longitude, latitude = coordinates
                    if geometry == 'Point' and longitude and latitude:
                        markers.append({
                            'uid': IUUID(venue),
                            'search_uid': brain.UID,
                            'url': brain.getURL(),
                            'title': brain.Title,
                            'tags': brain.Subject or [],
                            'start': brain.start or '',
                            'end': brain.end or '',
                            'geometry': {
                                'style': None,
                                'type': 'Point',
                                'coordinates': (longitude, latitude)
                            },
                            'latitude': latitude,
                            'longitude': longitude,
                        })
        else:
            markers = super(UshahidiMapView, self)._get_markers(brain)

        return markers
Ejemplo n.º 7
0
    def _get_markers(self, brain):
        """Return dict of marker details.

        Handle Info objects in special way.
        """
        markers = []
        if brain.portal_type == 'tbfac.Info':
            # get related Venues
            obj = brain.getObject()
            if obj is None:
                return []

            refs = obj.venue
            if not refs:
                return []

            for ref in refs:
                venue = ref.to_object
                geo = IGeoManager(venue, None)
                if geo and geo.isGeoreferenceable():
                    geometry, coordinates = geo.getCoordinates()
                    if not coordinates or len(coordinates) != 2:
                        continue
                    else:
                        longitude, latitude = coordinates
                    if geometry == 'Point' and longitude and latitude:
                        markers.append({
                            'uid': IUUID(venue),
                            'search_uid': brain.UID,
                            'url': brain.getURL(),
                            'title': brain.Title,
                            'tags': brain.Subject or [],
                            'start': brain.start or '',
                            'end': brain.end or '',
                            'geometry': {
                                'style': None,
                                'type': 'Point',
                                'coordinates': (longitude, latitude)},
                            'latitude': latitude,
                            'longitude': longitude,
                        })
        else:
            markers = super(UshahidiMapView, self)._get_markers(brain)

        return markers
    def index_object(self, documentId, obj, threshold=None):
        """index an object, normalizing the indexed value to its bounds

           o Objects which have 'None' as indexed value are *omitted*,
             by design.

        'documentId' is the integer ID of the document.
        'obj' is the object to be indexed.
        """
        returnStatus = 0
        try:
            geoitem=IGeoManager(obj)
        except:
            return 0
        if geoitem.wkt:
            geometry = wkt.loads(geoitem.wkt)
        else:
            geometry = None
        if geoitem.isGeoreferenceable() and geoitem.getCoordinates()[1]:
            newValue = geoitem.wkt
            if newValue is callable:
                newValue = newValue()
            oldValue = self.backward.get(documentId, _marker )

            if newValue is _marker:
                if oldValue is not _marker:
                    self.rtree.delete(documentId, wkt.loads(oldValue).bounds)
                    try:
                        del self.backward[documentId]
                    except ConflictError:
                        raise
                    except:
                        pass
            else:
                if oldValue is not _marker and newValue!=oldValue:
                    self.rtree.delete(documentId, wkt.loads(oldValue).bounds)
                if geometry:
                    self.rtree.add(documentId, geometry.bounds)
                self.backward[documentId] = newValue

            returnStatus = 1

        return returnStatus