def _parse_activities_response(self, jsonBody): """ """ activities = [] data = json.loads(str(jsonBody)) for activity in data['data']: # Create a new activity a = Activity(id=activity['id'], version=activity['version']) # Get the coords and set the geometry # Check first the geometry type # Handle MultiPoint geometries if activity['geometry']['type'].lower() == "multipoint": points = [] for coords in activity['geometry']['coordinates']: points.append(QgsPoint(coords[0], coords[1])) a.setGeometry(QgsGeometry.fromMultiPoint(points)) # Handle Point geometries if activity['geometry']['type'].lower() == "point": coords = activity['geometry']['coordinates'] a.setGeometry(QgsGeometry.fromPoint(QgsPoint(coords[0], coords[1]))) # Append it to the list activities.append(a) return activities
def _createNewActivity(id=None, otherActivity=None): # Connect to the protocol signal self.connect(self.activityProtocol, SIGNAL("created( bool, int, QString )"), _createNewActivityFinished) # Create a new Uuid if id is not None: uid = QPlainUuid(id) else: uid = QPlainUuid(QUuid.createUuid()) tagGroups = list(TagGroup() for i in range(len(groups))) # attrs is a dictionary: key = field index, value = QgsFeatureAttribute # show all attributes and their values self.log("Attribute list:") for (k, attr) in attrs.iteritems(): if k is not identifierColumnIndex: self.log("%s: %s" % (fieldIndexMap[k], attr.toString())) # First search the correct taggroup to append attributeName = provider.fields()[k].name() currentTagGroup = 0 for g in groups: if attributeName in g: break else: currentTagGroup += 1 if attr is not None and attr.toString() != '': tag = Tag(key=fieldIndexMap[k], value=attr.toString()) tagGroups[currentTagGroup].addTag(tag) if tagGroups[currentTagGroup].mainTag() is None: tagGroups[currentTagGroup].setMainTag(tag) a = Activity(id=uid) a.setGeometry(feature.geometry()) for tg in tagGroups: if len(tg.tags) > 0: a.addTagGroup(tg) wrapperObj = {} wrapperObj['activities'] = [a.createDiff(otherActivity)] self.activityProtocol.add(json.dumps(wrapperObj, sort_keys=True, indent=4 * ' '))
def _parse_activities_response(self, jsonBody): """ """ activities = [] data = json.loads(str(jsonBody)) for activity in data["data"]: # Create a new activity a = Activity(id=activity["id"], version=activity["version"]) # Get the point coords and set the geometry coords = activity["geometry"]["coordinates"] a.setGeometry(QgsGeometry.fromPoint(QgsPoint(coords[0], coords[1]))) # Append it to the list activities.append(a) return activities