Example #1
0
class transit(models.Model):
    transit_id = models.AutoField(null=False, primary_key=True)
    oskari_code = models.BigIntegerField(null=False)
    scenario = models.ForeignKey(scenario, on_delete=models.CASCADE)
    fclass = models.CharField(max_length=100, null=False)
    location = models.GeometryField(srid=4326)
    buffer = models.GeometryField(srid=4326, null=True)

    class Meta:
        db_table = "transit"
        unique_together = (("scenario", "oskari_code"), )
        indexes = [
            models.Index(fields=[
                'scenario',
            ]),
            models.Index(fields=[
                'fclass',
            ]),
        ]

    @property
    def transit_info(self):
        return self.transit_info_set.all()
Example #2
0
class PCT(models.Model):
    """
    PCTs or CCGs (depending on date).
    """

    PCT_ORG_TYPES = (
        ("CCG", "CCG"),
        ("PCT", "PCT"),
        ("H", "Hub"),
        ("Unknown", "Unknown"),
    )
    code = models.CharField(
        max_length=3, primary_key=True, help_text="Primary care trust code"
    )

    # These are NULLable, because not every PCT belongs to either a
    # RegionalTeam or an STP.  Specifically, we create PCT objects when
    # importing prescribing data if the PCT is not otherwise in our database.
    regional_team = models.ForeignKey(RegionalTeam, null=True, on_delete=models.PROTECT)
    stp = models.ForeignKey(STP, null=True, on_delete=models.PROTECT)

    ons_code = models.CharField(max_length=9, null=True, blank=True)
    name = models.CharField(max_length=200, null=True, blank=True)
    org_type = models.CharField(max_length=9, choices=PCT_ORG_TYPES, default="Unknown")
    boundary = models.GeometryField(null=True, blank=True, srid=4326)
    centroid = models.PointField(null=True, blank=True, srid=4326)
    open_date = models.DateField(null=True, blank=True)
    close_date = models.DateField(null=True, blank=True)
    address = models.CharField(max_length=400, null=True, blank=True)
    postcode = models.CharField(max_length=10, null=True, blank=True)

    objects = models.GeoManager()

    def __unicode__(self):
        return self.name or ""

    @property
    def cased_name(self):
        return nhs_titlecase(self.name)

    @property
    def name_and_status(self):
        if self.close_date:
            return self.cased_name + " (closed)"
        else:
            return self.cased_name

    def get_absolute_url(self):
        return reverse("ccg_home_page", kwargs={"ccg_code": self.code})
Example #3
0
class Location(models.Model):
    name = models.CharField(max_length=255)  # e.g., "35th Ward"
    normalized_name = models.CharField(max_length=255, db_index=True)
    slug = models.CharField(max_length=32, db_index=True)
    location_type = models.ForeignKey(LocationType)
    location = models.GeometryField(null=True)
    centroid = models.PointField(null=True)
    display_order = models.SmallIntegerField()
    city = models.CharField(max_length=255)
    source = models.CharField(max_length=64)
    area = models.FloatField(blank=True, null=True)  # in square meters
    population = models.IntegerField(blank=True,
                                     null=True)  # from the 2000 Census
    user_id = models.IntegerField(blank=True, null=True)
    is_public = models.BooleanField()
    description = models.TextField(blank=True)
    creation_date = models.DateTimeField(blank=True, null=True)
    last_mod_date = models.DateTimeField(blank=True, null=True)
    objects = models.GeoManager()

    class Meta:
        unique_together = (('slug', 'location_type'), )

    def __unicode__(self):
        return self.name

    def url(self):
        return '/locations/%s/%s/' % (self.location_type.slug, self.slug)

    def rss_url(self):
        return '/rss%s' % self.url()

    def alert_url(self):
        return '%salerts/' % self.url()

    def edit_url(self):
        return '/locations/%s/edit/%s/' % (self.location_type.slug, self.slug)

    # Give Location objects a "pretty_name" attribute for interoperability with
    # Block objects. (Parts of our app accept either a Block or Location.)
    def _get_name(self):
        return self.name

    pretty_name = property(_get_name)

    def _is_custom(self):
        return self.location_type.slug == 'custom'

    is_custom = property(_is_custom)
Example #4
0
class Activity(models.Model):
    id = models.AutoField(primary_key=True)
    activity_identifier = models.CharField(max_length=255, null=False)
    fk_changeset = models.IntegerField()
    point = gismodels.GeometryField(srid=4326, spatial_index=True, dim=2)
    fk_status = models.IntegerField()
    version = models.IntegerField()
    reliability = models.IntegerField()
    previous_version = models.IntegerField()
    timestamp_entry = models.DateTimeField()
    fk_user_review = models.IntegerField()
    timestamp_review = models.DateTimeField()
    comment_review = models.CharField(max_length=255)
    fk_profile = models.IntegerField()

    class Meta:
        app_label = 'from_v1'
        db_table = "activities"

    @property
    def identifier(self):
        return self.activity_identifier

    @property
    def tag_groups(self):
        return A_Tag_Group.objects.using('lo').filter(fk_activity=self.id)

    def __str__(self):
        """
        if self.point is None:
            geom = '-'
        else:
            geom = wkb.loads(str(self.point.geom_wkb)).wkt
        """
        geom = '***'
        return (
            '<Activity> id [ %s ] | activity_identifier [ %s ] | fk_changeset '
            '[ %s ] | point [ %s ] | fk_status [ %s ] | version [ %s ] | '
            'previous_version [ %s ] | fk_user_review [ %s ] | '
            'timestamp_review [ %s ] | comment_review [ %s ] | fk_profile [ %s'
            ' ]' % (self.id, self.activity_identifier, self.fk_changeset, geom,
                    self.fk_status, self.version, self.previous_version,
                    self.fk_user_review, self.timestamp_review,
                    self.comment_review, self.fk_profile))

    def get_comments(self):
        return DBSession.query(Comment).\
            filter(Comment.activity_identifier == self.activity_identifier).\
            all()
Example #5
0
class Quadricula(models.Model):
    id = models.CharField(primary_key=True, max_length=100)
    precision_m = models.FloatField(blank=True, null=True)
    resolution = models.FloatField(blank=True, null=True)
    code_utm_10 = models.CharField(max_length=4, blank=True, null=True)
    field_xmin = models.FloatField(
        db_column='_xmin', blank=True,
        null=True)  # Field renamed because it started with '_'.
    field_xmax = models.FloatField(
        db_column='_xmax', blank=True,
        null=True)  # Field renamed because it started with '_'.
    field_ymin = models.FloatField(
        db_column='_ymin', blank=True,
        null=True)  # Field renamed because it started with '_'.
    field_ymax = models.FloatField(
        db_column='_ymax', blank=True,
        null=True)  # Field renamed because it started with '_'.
    #quadre = models.TextField(blank=True, null=True)  # This field type is a guess.
    quadre = models.GeometryField()
    geom_4326 = models.GeometryField()  # modificado

    class Meta:
        managed = False
        db_table = 'quadricula'
Example #6
0
class mmu(models.Model):
    mmu_id = models.AutoField(null=False, primary_key=True)
    oskari_code = models.BigIntegerField(null=False)
    scenario = models.ForeignKey(scenario,
                                 on_delete=models.CASCADE,
                                 null=False)
    location = models.GeometryField(srid=4326)

    class Meta:
        unique_together = (("scenario", "oskari_code"), )
        db_table = "mmu"

    @property
    def mmu_info(self):
        return self.mmu_info_set.all()
Example #7
0
class Location(models.Model):
    location_id = models.BigAutoField(primary_key=True, blank=False)
    place_id = models.CharField(max_length=255, blank=False)
    address = models.CharField(max_length=255, blank=False)
    name = models.CharField(max_length=255 ,blank=False)
    coordinates = models_gis.GeometryField(blank=False)
    category = models.IntegerField(default=0, blank=False)
    # rating = models.FloatField(default=0, blank=False)
    # api에서 제공 X
    # used_time = models.FloatField(default=0, blank=False) # doulbe??
    image = models.CharField(max_length=1000, null=True, blank=False, default="no image")

    # 튜플의 대표값
    def __str__(self):
        return self.name
Example #8
0
class Mip2016(models.Model):
    """
    Meerjarig Investerings Programma
    """
    ogc_fid = models.IntegerField(primary_key=True)
    datum = models.CharField(max_length=255, blank=True, null=True)
    organisatie = models.CharField(max_length=255, blank=True, null=True)
    opdrachtgever = models.CharField(max_length=255, blank=True, null=True)
    nummer = models.CharField(max_length=255, blank=True, null=True)
    omschrijving = models.CharField(max_length=255, blank=True, null=True)
    wkb_geometry = models.GeometryField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'mip2016_clean'
Example #9
0
class Avistamiento(models.Model):
    """Modelo que representa un avistamiento de un animal, el campo geom es un modelo espacial vector punto"""
    id_avistamiento = models.AutoField(primary_key=True)
    geom = models.GeometryField()
    confirmado = models.BooleanField(default=False)
    fecha_hora = models.DateTimeField(blank=True, null=True)
    fotografia = models.ImageField()
    descripcion = models.TextField(max_length=1000, blank=True, null=True)
    usuario = models.ForeignKey(settings.AUTH_USER_MODEL,
                                on_delete=models.DO_NOTHING)
    animal = models.ForeignKey(Animal, on_delete=models.CASCADE)

    def __str__(self):
        return self.usuario.__str__() + ' , ' + self.animal.__str__() \
               + ' ' + self.fecha_hora.__str__() + '.'
Example #10
0
class SearchResultModel(models.Model):
    key = models.CharField(max_length=256, primary_key=True)
    identifier = models.CharField(max_length=256)
    project_name = models.CharField(max_length=256)
    committee = models.CharField(max_length=256)
    document_url = models.CharField(max_length=1024)
    start_date = models.DateField()
    audience = models.CharField(max_length=256)
    objective = models.CharField(max_length=1024)
    address = models.CharField(max_length=1024)
    record_type = models.CharField(max_length=1024)
    mpoly = models.GeometryField(default=None, null=True)
    mpoint = models.PointField()
    category = Category
    estimation = models.DecimalField(decimal_places=0, max_digits=50)
Example #11
0
class Gentity(models.Model):
    last_modified = models.DateTimeField(default=now,
                                         null=True,
                                         editable=False)
    name = models.CharField(max_length=200, blank=True)
    code = models.CharField(max_length=50, blank=True)
    remarks = models.TextField(blank=True)
    geom = models.GeometryField()

    class Meta:
        verbose_name_plural = "Gentities"
        ordering = ("name", )

    def __str__(self):
        return self.name or self.code or str(self.id)
Example #12
0
class Sage2GtaPrach(models.Model):
    id = models.AutoField()
    dia = models.TextField(blank=True, null=True)
    bts_name = models.TextField(blank=True, null=True)
    bin_ta = models.SmallIntegerField(blank=True, null=True)
    porcentaje = models.FloatField(blank=True, null=True)
    cant = models.IntegerField(blank=True, null=True)
    refarming = models.TextField(blank=True, null=True)
    band = models.SmallIntegerField(blank=True, null=True)
    initialfreq = models.IntegerField(blank=True, null=True)
    bin_geografico = models.GeometryField(srid=0, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'sage_2gta_prach'
Example #13
0
class Boundary(models.Model):
    """ educational boundaries """
    parent = models.ForeignKey('self', null=True)
    name = models.CharField(max_length=300)
    boundary_type = models.ForeignKey('BoundaryType')
    type = models.ForeignKey('common.InstitutionType', null=True)
    dise_slug = models.CharField(max_length=300, blank=True)
    geom = models.GeometryField(null=True)
    status = models.ForeignKey('common.Status')

    class Meta:
        unique_together = (('name', 'parent', 'type'), )

    def __unicode__(self):
        return '%s' % self.name
Example #14
0
class Geography(models.Model):
    """
        Represents a geographic shape such as a parcel, grid cell, line, etc. Other classes having features should
        associate to subclasses of this subclass it.
    """
    objects = models.GeoManager()
    geometry = models.GeometryField()
    # An identifier that uniquely identifies the source table that provided these geographies.
    source_table_id = models.IntegerField(null=False, db_index=True)
    # An identifier that uniquely a row from the source table, usually its id
    source_id = models.IntegerField(null=False, db_index=True, max_length=200)

    class Meta(object):
        abstract = True,
        app_label = 'main'
Example #15
0
class Routing(models.Model):
    objects = RoutingManager()

    origin = models.ForeignKey(Actor,
                               on_delete=models.CASCADE,
                               related_name='start')
    destination = models.ForeignKey(Actor,
                                    on_delete=models.CASCADE,
                                    related_name='end')
    geom = gis.GeometryField(null=True, blank=True)
    seq = models.TextField(null=True)
    distance = models.FloatField(default=0)

    def __str__(self):
        return '{} -> {}'.format(self.origin, self.destination)
Example #16
0
class OsmWays(models.Model):
    def __str__(self):
        return str(self.osm_id)

    osm_id = models.BigIntegerField(primary_key=True)
    members = HStoreField(null=True)
    attributes = HStoreField(null=True)
    tags = HStoreField(null=True)
    tag_name = models.TextField(blank=True, null=True)
    tag_value = models.TextField(blank=True, null=True)
    name = models.TextField(blank=True, null=True)
    the_geom = gis_models.GeometryField(blank=True, null=True)

    class Meta:
        db_table = 'osm_ways'
Example #17
0
class Unite(models.Model):
    code = models.CharField(max_length=16)
    nom = models.CharField(max_length=64)
    email = models.CharField(max_length=64)
    secours = models.CharField(max_length=64, blank=True, null=True)
    geom = models.GeometryField(blank=True, null=True)
    dept = models.CharField(max_length=3, blank=True, null=True)
    zoom = models.IntegerField()

    def __str__(self):
        return self.code + ' : ' + self.nom

    class Meta:
        managed = True
        db_table = 'unite'
Example #18
0
class AreeProtette(models.Model):
    _database = 'lifeten'
    id = models.IntegerField(primary_key=True)
    nome = models.TextField(db_column='name', blank=True)
    codice = models.TextField(blank=True)
    tipo_sic = models.CharField(max_length=2, blank=True)
    tipo = models.TextField(blank=True)
    geom = models.GeometryField(srid=25832, null=True, blank=True)
    objects = models.GeoManager()

    class Meta:
        db_table = u'aree_protette'

    def __unicode__(self):
        return smart_str(self.nome)
Example #19
0
class Instance(models.Model):
	id = models.CharField(primary_key=True, max_length=64, editable=False, blank=True, default=uuid4)
	fid = models.IntegerField()
	shapefile = models.ForeignKey(ShapeFile, related_name = "instances")
	position = geomodels.GeometryField()
	objects = geomodels.GeoManager()
	
	def save(self, *args, **kwargs):
		if SpatialReference(self.shapefile.srs) != SpatialReference(4326):
			ct = CoordTransform(SpatialReference(self.shapefile.srs), SpatialReference('WGS84'))
			self.position.transform(ct)
		super(Instance, self).save(*args, **kwargs)

	def __unicode__(self):
		return str(self.shapefile) + " - " + str(self.fid)
Example #20
0
class GWFlowSystem(models.Model):
    """
    7.6.17 GW_FlowSystem
    Flow path from recharge to discharge location, through hydrogeological units. It is
    related to a fluid body, and consists of a collection or aggregation of at least two specific
    flows, as well as possibly other flow systems.
    """
    gw_flow_path = models.GeometryField(
        verbose_name="GWFlowPath",
        help_text="The path of flow of a fluid through a container."
    )
    gw_part_of_system_flow = models.ForeignKey(
        "self", null=True, blank=True,
        on_delete=models.SET_NULL,
        help_text="Relates a flow system part to a flow system whole.")
Example #21
0
class Comunita(models.Model):
    _database = 'lifeten'
    id = models.IntegerField(primary_key=True)
    nome = models.CharField(db_column='name', max_length=80, blank=True)
    geom = models.GeometryField(db_column='wkb_geometry',
                                srid=25832,
                                null=True,
                                blank=True)
    objects = models.GeoManager()

    class Meta:
        db_table = u'comunita_valle'

    def __unicode__(self):
        return smart_str(self.nome)
class NeighborhoodVoterRegistrationByAgeGroup(models.Model):
    neighborhood = models.TextField()
    id = models.IntegerField(primary_key=True)
    year = models.IntegerField()
    pct_18_25 = models.FloatField()
    pct_26_32 = models.FloatField()
    pct_33_39 = models.FloatField()
    pct_40_49 = models.FloatField()
    pct_50_plus = models.FloatField()
    geom = models.GeometryField()
    

    class Meta:
        managed = False
        db_table = 'neighborhood_voters_ages_over_time_geom'
Example #23
0
class SoilData(models.Model):
    class Meta:
        db_table = 'soil_data'

    point = models.GeometryField(unique=True)
    date = models.DateField()
    field_name = models.CharField(max_length=100, default="")
    crop_name = models.CharField(max_length=100, default="")
    ph = models.FloatField()
    nitrogen = models.FloatField()
    phosphoric_acid = models.FloatField()
    potassium = models.FloatField()
    magnesium = models.FloatField()
    calsium = models.FloatField()
    remarks = models.CharField(max_length=100, default="")
Example #24
0
class Node(models.Model):
    dateTimeLabel = models.DateTimeField()
    g1 = models.IntegerField()
    L = models.IntegerField()
    T = models.CharField(max_length=200)
    BAT = models.IntegerField()
    ACC = models.CharField(max_length=200)
    G4 = models.CharField(max_length=200)
    # GPS = models.GeometryField(geography=True)
    GPS = models.GeometryField()
    dist = models.FloatField(null=True)
    TEMP = models.FloatField()
    CO = models.FloatField()
    NO2 = models.FloatField()
    fileInfo = models.ForeignKey(FileInfo, on_delete=models.CASCADE)
Example #25
0
class Person(models.Model):
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    #  Jards Macalé is an amazing brazilian musician! =]
    enjoy_jards_macale = models.BooleanField(default=True)
    like_metal_music = models.BooleanField(default=False)
    name = models.CharField(max_length=30)
    nickname = models.SlugField(max_length=36)
    age = models.IntegerField()
    bio = models.TextField()
    birthday = models.DateField()
    birth_time = models.TimeField()
    appointment = models.DateTimeField()
    blog = models.URLField()
    occupation = models.CharField(max_length=10, choices=OCCUPATION_CHOICES)
    uuid = models.UUIDField(primary_key=False)
    name_hash = models.BinaryField(max_length=16)
    days_since_last_login = models.BigIntegerField()
    duration_of_sleep = models.DurationField()
    email = models.EmailField()
    id_document = models.CharField(unique=True, max_length=10)

    try:
        from django.contrib.postgres.fields import ArrayField, HStoreField, JSONField
        from django.contrib.postgres.fields.citext import (
            CICharField,
            CIEmailField,
            CITextField,
        )

        acquaintances = ArrayField(models.IntegerField())
        data = JSONField()
        hstore_data = HStoreField()
        ci_char = CICharField(max_length=30)
        ci_email = CIEmailField()
        ci_text = CITextField()
    except ImportError:
        # Skip PostgreSQL-related fields
        pass

    if BAKER_GIS:
        geom = models.GeometryField()
        point = models.PointField()
        line_string = models.LineStringField()
        polygon = models.PolygonField()
        multi_point = models.MultiPointField()
        multi_line_string = models.MultiLineStringField()
        multi_polygon = models.MultiPolygonField()
        geom_collection = models.GeometryCollectionField()
Example #26
0
class Feature(models.Model):
    """
    Model to represent features created in the application.
    """
    aoi = models.ForeignKey(AOI, related_name='features', editable=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    objects = models.GeoManager()
    analyst = models.ForeignKey(User, editable=False)
    template = models.ForeignKey("FeatureType", on_delete=models.PROTECT)

    # Allow the user to save their own properties
    properties = JSONField(load_kwargs={}, blank=True, null=True)

    # These help the user identify features when data is exposed outside of the application (Geoserver).
    job = models.ForeignKey(Job, editable=False)
    project = models.ForeignKey(Project, editable=False)

    #Try this vs having individual models
    the_geom = models.GeometryField(blank=True, null=True)

    def geoJSON(self, as_json=True):
        """
        Returns geoJSON of the feature.
        Try to conform to https://github.com/mapbox/simplestyle-spec/tree/master/1.0.0
        """

        geojson = SortedDict()
        geojson["type"] = "Feature"
        geojson["properties"] = dict(id=self.id,
                                     template=self.template.id if hasattr(self.template, "id") else None
                                     )
        geojson["geometry"] = json.loads(self.the_geom.json)

        return json.dumps(geojson) if as_json else geojson

    def __unicode__(self):
        return "Feature created for {0}".format(self.aoi.name)

    def clean(self):
        obj_geom_type = self.the_geom.geom_type.lower()
        template_geom_type = self.template.type.lower()
        if obj_geom_type != template_geom_type:
            error_text = "Feature type {0} does not match the template's feature type {1}."
            raise ValidationError(error_text.format(obj_geom_type, template_geom_type))

    class Meta:
        ordering = ('-updated_at', 'aoi',)
class OsmWaysLegs(models.Model):
    osmId = models.BigIntegerField()
    geom = models.GeometryField()
    streetName = models.TextField()
    postalCode = models.TextField()
    highwayName = models.TextField()
    count = models.IntegerField(default=0)
    score = models.FloatField(default=0)
    score_array = ArrayField(models.FloatField(), default=list)
    velocity = models.FloatField(default=0)
    velocity_array = ArrayField(models.FloatField(), default=list)
    weekdayCount = models.IntegerField(default=0)
    morningCount = models.IntegerField(default=0)
    eveningCount = models.IntegerField(default=0)
    normalIncidentCount = models.IntegerField(default=0)
    scaryIncidentCount = models.IntegerField(default=0)
Example #28
0
class BikeLanes(models.Model):
    objectid = models.IntegerField(primary_key=True)
    tranplanid = models.CharField(max_length=50)
    segmentnam = models.CharField(max_length=50)
    status = models.CharField(max_length=50)
    facility = models.CharField(max_length=50)
    yearbuilt = models.IntegerField()
    yearretire = models.IntegerField()
    lengthmile = models.FloatField()
    shape_leng = models.FloatField()
    shape_le_1 = models.FloatField()
    geom = models.GeometryField()

    class Meta:
        managed = False
        db_table = 'bike_lanes'
Example #29
0
class BoundaryRegions(models.Model):
    class Meta:
        db_table = 'boundaries_regions'

    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=256, null=True)
    type = models.CharField(max_length=20, null=False, default="region")
    reg_code = models.CharField(max_length=20, null=True)
    reg_name = models.CharField(max_length=256, null=True)
    psgc_ph = models.CharField(max_length=20, null=True)
    geom = gismodels.GeometryField(srid=4326, null=True)
    parent = models.ForeignKey(BoundaryCountries,
                               db_column='parent_id',
                               null=True,
                               db_index=True,
                               on_delete=models.CASCADE)
Example #30
0
class Component(models.Model):
    """Drawable Component Database"""
    metadata = models.ForeignKey(Metadata)
    housenumber = models.CharField(max_length=5)
    shape = models.GeometryField(srid=4326)
    slum = models.ForeignKey(Slum)
    objects = models.GeoManager()

    def __unicode__(self):
        """Returns string representation of object"""
        return self.slum.name + ' - ' + self.metadata.name + ':' + self.housenumber

    class Meta:
        """Metadata for class Component"""
        verbose_name = 'Component'
        verbose_name_plural = 'Components'