Ejemplo n.º 1
0
    def to_internal_value(self, data):
        """
        Parse json data and return a multipoint object
        """
        if data is None:
            return None

        result = MultiPoint()
        points = super(MultiPointField, self).to_internal_value(data)

        for point in points:
            result.append(point)

        return result
Ejemplo n.º 2
0
def fnGetVDepartment(keyword):
	result = []

	if keyword == "":
		return result

	v_depart_list = CVDepartment.objects.filter(vname__contains=keyword).order_by('count').reverse()
	for i in v_depart_list:
		i.count = i.count+1
		i.save()

		vd_entry = {}
		vd_entry['type'] = 'department'
		vd_entry['name'] = i.vname
		vd_entry['id'] = i.pk

		p = Point(0,0)
		mp = MultiPoint(p)
		mp.remove(p)
		attributes_entry = {}
		attributes_entry['url'] = i.vlink
		children_list = []

		#e_depart_list = CEDepartment.objects.filter(cvdepartment_cedepartment_exact=i)
		e_depart_list = CEDepartment.objects.filter(evid__pk__exact=i.pk)
		for j in e_depart_list:
			j.count = j.count+1
			j.save()

			mp.append(j.ebid.loc)
			
			children_item = {}
			children_item['id'] = j.pk
			children_item['name'] = j.ename
			children_list.append(children_item)

		attributes_entry['children'] = children_list
		
		vd_entry['footprint'] = mp.wkt
		vd_entry['attributes'] = attributes_entry
		
		result.append(vd_entry)
	
	return result
Ejemplo n.º 3
0
 def create(self, validated_data):
     """
     Create and return a new `Snippet` instance, given the validated data.
     """
     print(validated_data.get('location_1'))
     print(validated_data.get('location_2'))
     temp_obj = dict()
     temp_obj['user_id'] = User.objects.get(pk=self.context.get("user_id"))
     try:
         temp_points = Activity_Record.objects.get(user_id_id=self.context.get("user_id")).location
         print(temp_points)
         g = temp_points
         g.append(Point((float)(validated_data.get('location_1')), (float)(validated_data.get('location_2'))))
         temp_obj['location'] = g
         return Activity_Record.objects.update(**temp_obj)
     except Activity_Record.DoesNotExist:
         g = MultiPoint()
         g.append(Point( (float) (validated_data.get('location_1') ),(float) (validated_data.get('location_2') )))
         temp_obj['location'] = g
         return Activity_Record.objects.create(**temp_obj)
Ejemplo n.º 4
0
def _find_country(loaded: List[dict]) -> [Country]:
    points = MultiPoint()

    shuffled_data = copy(loaded)
    random.shuffle(shuffled_data)  # noqa

    for data in shuffled_data:
        if len(points) == 2000:
            # exit if we already collected optimal number of points to proceed
            break

        try:
            point = Point(x=float(data['lon']), y=float(data['lat']))
        except (TypeError, ValueError, KeyError):
            continue

        if point == Point(x=0, y=0):
            continue

        points.append(point)

    countries = list(Country.objects.filter(geometry__intersects=points))

    if not countries:
        return None
    elif len(countries) == 1:
        return countries[0]
    else:
        countries_counter = Counter()
        for country in countries:
            instersections = country.geometry.intersection(points)
            if isinstance(instersections, Point):
                countries_counter[country] = 1
            else:
                countries_counter[country] = len(instersections)
        return countries_counter.most_common()[0][0]