| 44 | | |
|---|
| | 44 | def get_coords(coord_string, geomtype='point'): |
|---|
| | 45 | values = [float(v) for v in coord_string.split()] |
|---|
| | 46 | nvalues = len(values) |
|---|
| | 47 | npoints = nvalues/3 |
|---|
| | 48 | coords = [] |
|---|
| | 49 | for i in range(npoints): |
|---|
| | 50 | coords.append((values[3*i+1], values[3*i], values[3*i+2])) |
|---|
| | 51 | if geomtype == 'point': |
|---|
| | 52 | return coords[0] |
|---|
| | 53 | elif geomtype == 'line': |
|---|
| | 54 | return tuple(coords) |
|---|
| | 55 | elif geomtype == 'polygon': |
|---|
| | 56 | return (tuple(coords),) |
|---|
| | 57 | |
|---|
| | 58 | def coords_to_kml(geom): |
|---|
| | 59 | gtype = geom['type'] |
|---|
| | 60 | if gtype == 'Point': |
|---|
| | 61 | coords = (geom['coordinates'],) |
|---|
| | 62 | elif gtype == 'Polygon': |
|---|
| | 63 | coords = geom['coordinates'][0] |
|---|
| | 64 | else: |
|---|
| | 65 | coords = geom['coordinates'] |
|---|
| | 66 | tuples = ('%f,%f,%f' % c for c in coords) |
|---|
| | 67 | return ' '.join(tuples) |
|---|
| | 68 | |
|---|
| | 69 | |
|---|
| 56 | | info = item.getInfo(dims=2) |
|---|
| 57 | | geom_element = "<georss:%(geometryType)s>%(spatialCoordinates)s</georss:%(geometryType)s>" % info |
|---|
| 58 | | info.update({'geom_element': geom_element}) |
|---|
| | 86 | info = item.__geo_interface__ |
|---|
| | 87 | info.update({ |
|---|
| | 88 | 'hasPoint': item.hasPoint(), |
|---|
| | 89 | 'hasLineString': item.hasLineString(), |
|---|
| | 90 | 'hasPolygon': item.hasPolygon(), |
|---|
| | 91 | 'coords_georss': item.georef['spatialCoordinates'] |
|---|
| | 92 | }) |
|---|
| 67 | | info = item.getInfo() |
|---|
| 68 | | coords = item.getSpatialCoordinates() |
|---|
| 69 | | swapped_coords = [] |
|---|
| 70 | | for x in coords: |
|---|
| 71 | | swapped_coords.extend([str(x[1]), str(x[0]), str(x[2])]) |
|---|
| 72 | | info.update({'spatialCoordinates': ','.join(swapped_coords)}) |
|---|
| 73 | | geom_element = "<%s><coordinates>%s,%s,%s</coordinates></%s>" \ |
|---|
| 74 | | % (info['geometryType'].capitalize(), |
|---|
| 75 | | swapped_coords[0], swapped_coords[1], swapped_coords[2], |
|---|
| 76 | | info['geometryType'].capitalize()) |
|---|
| 77 | | desc_body = "<![CDATA[<p>%(description)s</p><p><a href=\"%(url)s\">%(title)s</a></p>]]>" % info |
|---|
| 78 | | info.update({'geom_element': geom_element, 'desc_body': desc_body}) |
|---|
| | 101 | info = item.__geo_interface__ |
|---|
| | 102 | info.update({ |
|---|
| | 103 | 'hasPoint': item.hasPoint(), |
|---|
| | 104 | 'hasLineString': item.hasLineString(), |
|---|
| | 105 | 'hasPolygon': item.hasPolygon(), |
|---|
| | 106 | 'coords_kml': coords_to_kml(info['geometry']) |
|---|
| | 107 | }) |
|---|
| 98 | | info = {'srs': member.getProperty('srs', None), |
|---|
| 99 | | 'geometryType': member.getProperty('geometryType', None), |
|---|
| 100 | | } |
|---|
| 101 | | |
|---|
| 102 | | values = member.getProperty('spatialCoordinates', '').split() |
|---|
| 103 | | nvalues = len(values) |
|---|
| 104 | | npoints = nvalues/3 |
|---|
| 105 | | coords = [] |
|---|
| 106 | | for i in range(npoints): |
|---|
| 107 | | coords.extend(values[3*i:3*i+2]) |
|---|
| 108 | | info['spatialCoordinates'] = ' '.join(coords) |
|---|
| | 127 | |
|---|
| | 128 | gtype = member.getProperty('geometryType', None) |
|---|
| | 129 | gcoords = member.getProperty('spatialCoordinates', '') |
|---|
| | 130 | if not gtype or not gcoords: |
|---|
| | 131 | # member is not georeferenced |
|---|
| | 132 | continue |
|---|
| | 133 | |
|---|
| | 134 | geom_type = gtype.capitalize() |
|---|
| | 135 | if geom_type == 'Line': |
|---|
| | 136 | geom_type = 'LineString' |
|---|
| | 137 | |
|---|
| | 138 | info = { |
|---|
| | 139 | 'geometry': { |
|---|
| | 140 | 'type': geom_type, |
|---|
| | 141 | 'coordinates': get_coords(gcoords), |
|---|
| | 142 | } |
|---|
| | 143 | } |
|---|
| 110 | | if not info['spatialCoordinates']: |
|---|
| 111 | | # member is not georeferenced |
|---|
| 112 | | continue |
|---|
| 113 | | |
|---|
| 114 | | info.update( |
|---|
| 115 | | {'id': id, |
|---|
| 116 | | 'title' : member.getProperty('fullname'), |
|---|
| 117 | | 'description' : member.getProperty('description'), |
|---|
| 118 | | 'location' : member.getProperty('location'), |
|---|
| 119 | | 'language' : member.getProperty('language'), |
|---|
| 120 | | 'url' : "%s/author/%s" % (folder.portal_url(), id), |
|---|
| 121 | | } |
|---|
| 122 | | ) |
|---|
| 123 | | |
|---|
| | 145 | info.update({ |
|---|
| | 146 | 'id': id, |
|---|
| | 147 | 'properties': { |
|---|
| | 148 | 'title': member.getProperty('fullname'), |
|---|
| | 149 | 'description' : member.getProperty('description'), |
|---|
| | 150 | 'location' : member.getProperty('location'), |
|---|
| | 151 | 'language' : member.getProperty('language'), |
|---|
| | 152 | 'link' : "%s/author/%s" % (folder.portal_url(), id), |
|---|
| | 153 | }, |
|---|
| | 154 | 'hasPoint': int(geom_type == 'Point'), |
|---|
| | 155 | 'hasLineString': int(geom_type == 'LineString'), |
|---|
| | 156 | 'hasPolygon': int(geom_type == 'Polygon'), |
|---|
| | 157 | 'coords_georss': gcoords, |
|---|
| | 158 | }) |
|---|
| | 159 | |
|---|
| 144 | | info = {'srs': member.getProperty('srs', None), |
|---|
| 145 | | 'geometryType': member.getProperty('geometryType'), |
|---|
| 146 | | 'spatialCoordinates': \ |
|---|
| 147 | | member.getProperty('spatialCoordinates', '') |
|---|
| | 178 | gtype = member.getProperty('geometryType', None) |
|---|
| | 179 | gcoords = member.getProperty('spatialCoordinates', '') |
|---|
| | 180 | if not gtype or not gcoords: |
|---|
| | 181 | # member is not georeferenced |
|---|
| | 182 | continue |
|---|
| | 183 | |
|---|
| | 184 | geom_type = gtype.capitalize() |
|---|
| | 185 | if geom_type == 'Line': |
|---|
| | 186 | geom_type = 'LineString' |
|---|
| | 187 | |
|---|
| | 188 | info = { |
|---|
| | 189 | 'geometry': { |
|---|
| | 190 | 'type': geom_type, |
|---|
| | 191 | 'coordinates': get_coords(gcoords), |
|---|
| 149 | | if not info['spatialCoordinates']: |
|---|
| 150 | | # member is not georeferenced |
|---|
| 151 | | continue |
|---|
| 152 | | |
|---|
| 153 | | # Swap coordinates for KML |
|---|
| 154 | | lat, lon, z = info['spatialCoordinates'].split() |
|---|
| 155 | | info.update({'spatialCoordinates': ' '.join([lon, lat, z])}) |
|---|
| 156 | | |
|---|
| 157 | | info.update( |
|---|
| 158 | | {'id': id, |
|---|
| 159 | | 'title' : member.getProperty('fullname'), |
|---|
| 160 | | 'description' : member.getProperty('description'), |
|---|
| 161 | | 'location' : member.getProperty('location'), |
|---|
| 162 | | 'language' : member.getProperty('language'), |
|---|
| 163 | | 'url' : "%s/author/%s" % (folder.portal_url(), id), |
|---|
| 164 | | } |
|---|
| 165 | | ) |
|---|
| 166 | | |
|---|
| 167 | | geom_type = info['geometryType'] or 'point' |
|---|
| 168 | | coords = [float(x) for x in info['spatialCoordinates'].split()] |
|---|
| 169 | | if len(coords) == 2: |
|---|
| 170 | | coords.append(0.0) |
|---|
| 171 | | try: |
|---|
| 172 | | geom_element = "<%s><coordinates>%f,%f,%f</coordinates></%s>" \ |
|---|
| 173 | | % (geom_type.capitalize(), |
|---|
| 174 | | coords[1], coords[0], coords[2], |
|---|
| 175 | | geom_type.capitalize()) |
|---|
| 176 | | except: |
|---|
| 177 | | print coords |
|---|
| 178 | | print info |
|---|
| 179 | | raise |
|---|
| 180 | | desc_body = "<![CDATA[<p>%(description)s</p><p><a href=\"%(url)s\">%(title)s</a></p>]]>" % info |
|---|
| 181 | | info.update({'geom_element': geom_element, 'desc_body': desc_body}) |
|---|
| 182 | | infos.append(info) |
|---|
| 183 | | return infos |
|---|
| 184 | | |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|
| | 195 | info.update({ |
|---|
| | 196 | 'id': id, |
|---|
| | 197 | 'properties': { |
|---|
| | 198 | 'title': member.getProperty('fullname'), |
|---|
| | 199 | 'description' : member.getProperty('description'), |
|---|
| | 200 | 'location' : member.getProperty('location'), |
|---|
| | 201 | 'language' : member.getProperty('language'), |
|---|
| | 202 | 'link' : "%s/author/%s" % (folder.portal_url(), id), |
|---|
| | 203 | }, |
|---|
| | 204 | 'hasPoint': int(geom_type == 'Point'), |
|---|
| | 205 | 'hasLineString': int(geom_type == 'LineString'), |
|---|
| | 206 | 'hasPolygon': int(geom_type == 'Polygon'), |
|---|
| | 207 | 'coords_kml': coords_to_kml(info['geometry']), |
|---|
| | 208 | }) |
|---|
| | 209 | |
|---|
| | 210 | # Work around OpenLayers bug |
|---|
| | 211 | if len(info['properties']['description']) < 1: |
|---|
| | 212 | info['properties']['description'] = 'No description' |
|---|
| | 213 | if len(info['properties']['title']) < 1: |
|---|
| | 214 | info['properties']['title'] = 'No title' |
|---|
| | 215 | |
|---|
| | 216 | infos.append(info) |
|---|
| | 217 | return infos |
|---|
| | 218 | |
|---|