Exemplo n.º 1
0
def get_geoms():
    cntr = GEOSGeometry('SRID=3857;POINT(-13842474.0 5280123.1)')

    stand_geoms = []
    for i in range(NUM_STANDS):
        cntr.set_x(cntr.x + 150)
        g1 = cntr.buffer(75)
        g1.transform(settings.GEOMETRY_DB_SRID)
        stand_geoms.append(wkt.loads(g1.wkt))

    casc_poly = cascaded_union(stand_geoms)

    if casc_poly.type == 'MultiPolygon':
        polys = []
        for c in casc_poly:
            interiors = [
                x for x in c.interiors
                if Polygon(x).area > settings.SLIVER_THRESHOLD
            ]
            polys.append(Polygon(shell=c.exterior, holes=interiors))
    elif casc_poly.type == 'Polygon':
        interiors = [
            x for x in casc_poly.interiors
            if Polygon(x).area > settings.SLIVER_THRESHOLD
        ]
        polys = [Polygon(shell=casc_poly.exterior, holes=interiors)]

    property_geom = MultiPolygon(polys)

    return stand_geoms, property_geom
Exemplo n.º 2
0
class UserProfile(UserenaBaseProfile, gis_models.Model):
    user = gis_models.OneToOneField(User, unique=True,verbose_name=_('user'),related_name='profile')
    interests = gis_models.ManyToManyField(Interest, related_name='+')
    selectedInterest = gis_models.ForeignKey(Interest, related_name='+', null=True, blank=True)
    settings = gis_models.OneToOneField('UserSettings')

    city = gis_models.CharField(max_length=100, null=True) # TODO: change to something like 'locationString'
    location = gis_models.PointField(null=True)
    objects = gis_models.GeoManager()

    def isNewUser(self):
        return self.location == None
        #return (self.interests.count() == 0 or self.selectedInterest == None or self.location == None)

    def save(self, force_insert=False, force_update=False, using=None):
        if self.pk is None:
            self.settings = UserSettings.objects.create()
        self.settings.save()
        super(UserProfile, self).save()

    def setLocation(self, lat, lon, city=None):
        if city:
            self.city = city
        if not self.location:
            self.location = GEOSGeometry('POINT(%s %s)' % (lat, lon))
        else:
            self.location.set_x(float(lat))
            self.location.set_y(float(lon))
        self.save()
def get_geoms():
    cntr = GEOSGeometry("SRID=3857;POINT(-13842474.0 5280123.1)")

    stand_geoms = []
    for i in range(NUM_STANDS):
        cntr.set_x(cntr.x + 150)
        g1 = cntr.buffer(75)
        g1.transform(settings.GEOMETRY_DB_SRID)
        stand_geoms.append(wkt.loads(g1.wkt))

    casc_poly = cascaded_union(stand_geoms)

    if casc_poly.type == "MultiPolygon":
        polys = []
        for c in casc_poly:
            interiors = [x for x in c.interiors if Polygon(x).area > settings.SLIVER_THRESHOLD]
            polys.append(Polygon(shell=c.exterior, holes=interiors))
    elif casc_poly.type == "Polygon":
        interiors = [x for x in casc_poly.interiors if Polygon(x).area > settings.SLIVER_THRESHOLD]
        polys = [Polygon(shell=casc_poly.exterior, holes=interiors)]

    property_geom = MultiPolygon(polys)

    return stand_geoms, property_geom
Exemplo n.º 4
0
from trees.models import Stand, Scenario, Strata, ForestProperty, SpatialConstraint, Rx, ScenarioStand
from django.contrib.auth.models import User
from django.test.client import Client
from django.contrib.gis.geos import GEOSGeometry
from shapely.ops import cascaded_union
from shapely.geometry import Polygon, MultiPolygon
from shapely import wkt

cntr = GEOSGeometry('SRID=3857;POINT(-13842500.0 5280100.0)')

NUM_STANDS = 10 * 10 
geoms = []
for i in range(int(NUM_STANDS**0.5)):
    cntr.set_y(cntr.y - 150)
    for j in range(int(NUM_STANDS**0.5)):
        cntr.set_x(cntr.x + 150)
        g1 = cntr.buffer(75).envelope
        g1.transform(settings.GEOMETRY_DB_SRID)
        geoms.append(wkt.loads(g1.wkt))
    cntr.set_x(cntr.x - int(NUM_STANDS**0.5)*150)

casc_poly = cascaded_union(geoms)

if casc_poly.type == 'MultiPolygon':
    polys = []
    for c in casc_poly:
        interiors = [x for x in c.interiors if Polygon(x).area > settings.SLIVER_THRESHOLD]
        polys.append(Polygon(shell=c.exterior, holes=interiors))
elif casc_poly.type == 'Polygon':
    interiors = [x for x in casc_poly.interiors if Polygon(x).area > settings.SLIVER_THRESHOLD]
    polys = [Polygon(shell=casc_poly.exterior, holes=interiors)]
import time
from trees.models import Stand, Scenario, Strata, ForestProperty, ScenarioNotRunnable
from django.contrib.auth.models import User
from django.test.client import Client
from django.contrib.gis.geos import GEOSGeometry
from shapely.ops import cascaded_union
from shapely.geometry import Polygon, MultiPolygon
from shapely import wkt


cntr = GEOSGeometry('SRID=3857;POINT(-13842474.0 5280123.1)')

NUM_STANDS = 2
geoms = []
for i in range(NUM_STANDS):
    cntr.set_x(cntr.x + 150)
    g1 = cntr.buffer(75)
    g1.transform(settings.GEOMETRY_DB_SRID)
    geoms.append(wkt.loads(g1.wkt))

casc_poly = cascaded_union(geoms)

if casc_poly.type == 'MultiPolygon':
    polys = []
    for c in casc_poly:
        interiors = [x for x in c.interiors if Polygon(x).area > settings.SLIVER_THRESHOLD]
        polys.append(Polygon(shell=c.exterior, holes=interiors))
elif casc_poly.type == 'Polygon':
    interiors = [x for x in casc_poly.interiors if Polygon(x).area > settings.SLIVER_THRESHOLD]
    polys = [Polygon(shell=casc_poly.exterior, holes=interiors)]
import json
import time
from trees.models import Stand, Scenario, Strata, ForestProperty, ScenarioNotRunnable
from django.contrib.auth.models import User
from django.test.client import Client
from django.contrib.gis.geos import GEOSGeometry
from shapely.ops import cascaded_union
from shapely.geometry import Polygon, MultiPolygon
from shapely import wkt

cntr = GEOSGeometry('SRID=3857;POINT(-13842474.0 5280123.1)')

NUM_STANDS = 2
geoms = []
for i in range(NUM_STANDS):
    cntr.set_x(cntr.x + 150)
    g1 = cntr.buffer(75)
    g1.transform(settings.GEOMETRY_DB_SRID)
    geoms.append(wkt.loads(g1.wkt))

casc_poly = cascaded_union(geoms)

if casc_poly.type == 'MultiPolygon':
    polys = []
    for c in casc_poly:
        interiors = [
            x for x in c.interiors
            if Polygon(x).area > settings.SLIVER_THRESHOLD
        ]
        polys.append(Polygon(shell=c.exterior, holes=interiors))
elif casc_poly.type == 'Polygon':
Exemplo n.º 7
0
from trees.models import Stand, Scenario, Strata, ForestProperty, SpatialConstraint, Rx, ScenarioStand
from django.contrib.auth.models import User
from django.test.client import Client
from django.contrib.gis.geos import GEOSGeometry
from shapely.ops import cascaded_union
from shapely.geometry import Polygon, MultiPolygon
from shapely import wkt

cntr = GEOSGeometry('SRID=3857;POINT(-13842500.0 5280100.0)')

NUM_STANDS = 10 * 10
geoms = []
for i in range(int(NUM_STANDS**0.5)):
    cntr.set_y(cntr.y - 150)
    for j in range(int(NUM_STANDS**0.5)):
        cntr.set_x(cntr.x + 150)
        g1 = cntr.buffer(75).envelope
        g1.transform(settings.GEOMETRY_DB_SRID)
        geoms.append(wkt.loads(g1.wkt))
    cntr.set_x(cntr.x - int(NUM_STANDS**0.5) * 150)

casc_poly = cascaded_union(geoms)

if casc_poly.type == 'MultiPolygon':
    polys = []
    for c in casc_poly:
        interiors = [
            x for x in c.interiors
            if Polygon(x).area > settings.SLIVER_THRESHOLD
        ]
        polys.append(Polygon(shell=c.exterior, holes=interiors))