class PermitRequestGeoTime(models.Model): """ Permit location in space and time """ permit_request = models.ForeignKey("PermitRequest", on_delete=models.CASCADE, related_name="geo_time") starts_at = models.DateTimeField(_("Date planifiée de début"), blank=True, null=True) ends_at = models.DateTimeField(_("Date planifiée de fin"), blank=True, null=True) comment = models.CharField(_("Commentaire"), max_length=1024, blank=True) external_link = models.URLField(_("Lien externe"), blank=True) geom = geomodels.GeometryCollectionField(_("Localisation"), null=True, srid=2056) history = HistoricalRecords() class Meta: verbose_name = _("3.3 Consultation de l'agenda et de la géométrie") verbose_name_plural = _("3.3 Consultation des agenda et géométries") indexes = [ models.Index(fields=["starts_at"]), models.Index(fields=["ends_at"]), ]
class Geotag(models.Model): """ A simple wrapper around the GeoDjango field types """ # Content-object field content_type = models.ForeignKey(ContentType, related_name="content_type_set_for_%(class)s") object_id = models.PositiveIntegerField(_('object ID'), max_length=50) tagged_obj = generic.GenericForeignKey(ct_field="content_type", fk_field="object_id") point = models.PointField(**field_kwargs('point')) multilinestring = models.MultiLineStringField(**field_kwargs('multi-line')) line = models.LineStringField(**field_kwargs('line')) polygon = models.PolygonField(**field_kwargs('polygon')) geometry_collection = models.GeometryCollectionField( **field_kwargs('geometry collection')) objects = GeotagManager() def get_geom(self): """Returns the geometry in use or None""" for geom_type in ('point', 'line', 'multilinestring', 'polygon', 'geometry_collection'): geom = getattr(self, geom_type) if geom: return geom return None
class Feature(models.Model): shapefile = models.ForeignKey(Shapefile) geom_point = models.PointField(srid=4326, blank=True, null=True) geom_multipoint = \ models.MultiPointField(srid=4326, blank=True, null=True) geom_multilinestring = \ models.MultiLineStringField(srid=4326, blank=True, null=True) geom_multipolygon = \ models.MultiPolygonField(srid=4326, blank=True, null=True) geom_geometrycollection = \ models.GeometryCollectionField(srid=4326, blank=True, null=True) objects = models.GeoManager() def __str__(self): return str(self.id) def __unicode__(self): for geom in [ self.geom_singlepoint, self.geom_multipoint, self.geom_multilinestring, self.geom_multipolygon, self.geom_geometrycollection ]: if geom != None: return str(geom) return "id " + str(self.id)
class Zone(gismodels.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=64) geom = gismodels.GeometryCollectionField(spatial_index=True) colour = models.CharField(max_length=7) event = models.ForeignKey(Event, related_name='zones', null=True, blank=True, default=None) objects = gismodels.GeoManager() author = models.ForeignKey(User, related_name='zones', null=True, blank=True, default=None) def __repr__(self): return '<Zone %s>' % self.name def __str__(self): return self.name class Meta: managed = True
class License(BaseDocumentModel): license_number = models.CharField(max_length=255, null=True, blank=True) description = models.TextField(null=True, blank=True) geometry = gis_models.GeometryCollectionField(blank=True, null=True) type = models.CharField(max_length=255, null=True, blank=True) entity = models.CharField(max_length=255, null=True, blank=True) diameter = models.PositiveIntegerField(null=True, blank=True) material = models.CharField(max_length=255, null=True, blank=True) end_date = models.CharField(max_length=255, null=True, blank=True) status = models.CharField(max_length=255, null=True, blank=True) agreement_type = models.CharField(max_length=255, null=True, blank=True) township = pg_fields.ArrayField( models.PositiveIntegerField(null=True), help_text=ARRAY_FIELD_HELP_TEXT, default=list ) range = pg_fields.ArrayField( models.PositiveIntegerField(null=True), help_text=ARRAY_FIELD_HELP_TEXT, default=list ) section = pg_fields.ArrayField( models.PositiveIntegerField(null=True), help_text=ARRAY_FIELD_HELP_TEXT, default=list ) source_file = models.FileField(upload_to='LICENSES')
class Pizzeria(geo_models.Model): hq = geo_models.PointField() directions = geo_models.LineStringField() floor_plan = geo_models.PolygonField() locations = geo_models.MultiPointField() routes = geo_models.MultiLineStringField() delivery_areas = geo_models.MultiPolygonField() all_the_things = geo_models.GeometryCollectionField()
class CommunityActivity(models.Model): code = models.CharField(max_length=256, primary_key=True) metadata = models.OneToOneField('CommunityActivityMetaData', null=True, on_delete=models.CASCADE, to_field='code') mpoly = models.MultiPointField() gc = models.GeometryCollectionField(default=None, null=True)
class DistrictMinorWork(models.Model): identifier = models.CharField(max_length=256, primary_key=True) project_name = models.CharField(max_length=256) metadata = models.OneToOneField('DistrictMinorWorkMetaData', null=True, on_delete=models.CASCADE, to_field='identifier') mpoly = models.MultiPolygonField() gc = models.GeometryCollectionField(default=None, null=True)
class ModelForGeoDjango(geomodels.Model): geometry = geomodels.GeometryField() point = geomodels.PointField() line_string = geomodels.LineStringField() polygon = geomodels.PolygonField() multi_point = geomodels.MultiPointField() multi_line_string = geomodels.MultiLineStringField() multi_polygon = geomodels.MultiPolygonField() geometry_collection = geomodels.GeometryCollectionField()
class City(gis_models.Model): insee = models.CharField(u'code INSEE de la commune', max_length=5) name = models.CharField(u'Nom de la commune', max_length=120, default="", blank=True) geometry = gis_models.GeometryCollectionField(blank=True, null=True) def save(self, *args, **kwargs): if self.geometry: pass else: if self.insee in [ "75101", "75102", "75103", "75104", "75105", "75106", "75107", "75108", "75109", "75110", "75111", "75112", "75113", "75114", "75115", "75116", "75117", "75118", "75119", "75120" ]: code_INSEE = "75056" elif self.insee in [ "69381", "69382", "69383", "69384", "69385", "69386", "69387", "69388", "69389" ]: code_INSEE = "69123" elif self.insee in [ "13201", "13202", "13203", "13204", "13205", "13206", "13207", "13208", "13209", "13210", "13211", "13212", "13213", "13214", "13215", "13216" ]: code_INSEE = "13055" else: code_INSEE = self.insee r = requests.get( 'https://geo.api.gouv.fr/communes?fields=nom,contour&code=%s' % (code_INSEE)) try: coord = r.json()[0]['contour'] nom = r.json()[0]['nom'] except: pass try: mpoly = GEOSGeometry(json.dumps(coord)) self.geometry = GeometryCollection(mpoly) self.name = nom except: pass super(City, self).save(*args, **kwargs) def centroid(self): return self.geometry.centroid def __unicode__(self): return "%s (insee : %s)" % (self.name, self.insee) class Meta: verbose_name = u"Localisation"
class Layers(models.Model): layers_category = models.ForeignKey(LayersCategory, on_delete=models.CASCADE, related_name='categories') name = models.CharField(unique=True, max_length=200) geom = models.GeometryCollectionField() def __str__(self): return self.name class Meta: verbose_name_plural = 'Layers'
class GenericGeoLocation(models.Model): name = models.CharField(max_length=255) geo_json_file = models.FileField(blank=True, null=True) geo_collection = models.GeometryCollectionField(blank=True, null=True) def __str__(self): return self.name class Meta: abstract = True
class Infrastructure(models.Model): def __unicode__(self): return self.name year = models.ForeignKey(Year) name = models.CharField(max_length=50) location_point = models.PointField(null=True, blank=True) location_line = models.LineStringField(null=True, blank=True) location_poly = models.PolygonField(null=True, blank=True) location_multigeom = models.GeometryCollectionField(null=True, blank=True) tags = models.CharField(max_length=256) objects = models.GeoManager()
class OtherRelations(models.Model): ogc_fid = models.AutoField(primary_key=True) wkb_geometry = models.GeometryCollectionField(blank=True, null=True) osm_id = models.CharField(max_length=500, blank=True, null=True) name = models.CharField(max_length=500, blank=True, null=True) type = models.CharField(max_length=500, blank=True, null=True) other_tags = HStoreField() class Meta: managed = False db_table = 'other_relations'
class ModelForGeoDjango(geomodels.Model): geometry = geomodels.GeometryField() point = geomodels.PointField() line_string = geomodels.LineStringField() polygon = geomodels.PolygonField() multi_point = geomodels.MultiPointField() multi_line_string = geomodels.MultiLineStringField() multi_polygon = geomodels.MultiPolygonField() geometry_collection = geomodels.GeometryCollectionField() class Meta: app_label = 'django_dynamic_fixture'
class OsmData(models.Model): """ OSM Data information from a submission instance """ instance = models.ForeignKey('logger.Instance', related_name='osm_data') xml = models.TextField() osm_id = models.CharField(max_length=20) osm_type = models.CharField(max_length=10, default='way') tags = JSONField(default=dict, null=False) geom = models.GeometryCollectionField() filename = models.CharField(max_length=255) field_name = models.CharField(max_length=255, blank=True, default='') date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) deleted_at = models.DateTimeField(null=True, default=None) class Meta: app_label = 'logger' unique_together = ('instance', 'field_name') @classmethod def get_tag_keys(cls, xform, field_path, include_prefix=False): query = OsmData.objects.raw( '''SELECT DISTINCT JSONB_OBJECT_KEYS(tags) as id FROM "logger_osmdata" INNER JOIN "logger_instance" ON ( "logger_osmdata"."instance_id" = "logger_instance"."id" ) WHERE "logger_instance"."xform_id" = %s AND field_name = %s''', # noqa [xform.pk, field_path] ) prefix = field_path + u':' if include_prefix else u'' return sorted([prefix + key.id for key in query]) def get_tags_with_prefix(self): doc = { self.field_name + ':' + self.osm_type + ':id': self.osm_id } for k, v in self.tags.items(): doc[self.field_name + ':' + k] = v return doc def _set_centroid_in_tags(self): self.tags = self.tags if isinstance(self.tags, dict) else {} if self.geom is not None: # pylint: disable=E1101 self.tags.update({ "ctr:lon": self.geom.centroid.x, "ctr:lat": self.geom.centroid.y, }) def save(self, *args, **kwargs): self._set_centroid_in_tags() super(OsmData, self).save(*args, **kwargs)
class Stop(models.Model): gtfs_stop_id = models.IntegerField(db_index=True, unique=True) name = models.CharField(max_length=50) point = models.PointField() parkings = models.GeometryCollectionField(null=True, blank=True) objects = models.GeoManager() def get_absolute_url(self): return reverse('core:stop', args=(self.id, )) def __str__(self): return self.name
class RecordShapeEdit(models.Model): record = models.ForeignKey(Record, on_delete=models.CASCADE) data = models.GeometryCollectionField("data") timestamp = models.DateTimeField('timestamp') user = models.ForeignKey(User) def __str__(self): return "RecordTextAttribute " + self.record.currentName + "," + self.attrib.name def Xml(self): return "<RecordShapeEdit id=\"{}\" recordId=\"{}\" data=\"{}\" timestamp=\"{}\" user=\"{}\" userId=\"{}\"/>\n".format( self.id, self.record.id, self.data.wkt, self.timestamp, self.user.username, self.user.id)
class AlienActivity(models.Model): incident_name = models.CharField(max_length=255) landings = models.MultiPointField() strange_lights = models.GeometryCollectionField() chemtrails = models.MultiLineStringField() objects = models.GeoManager() class Meta: verbose_name_plural = u"Alien activities" def __unicode__(self): return self.incident_name
class Feature(models.Model): dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE, related_name="features") raster = models.RasterField(null=True, blank=True) geom_point = models.PointField(srid=4326, blank=True, null=True) geom_multipoint = models.MultiPointField(srid=4326, blank=True, null=True) geom_multilinestring = models.MultiLineStringField(srid=4326, blank=True, null=True) geom_multipolygon = models.MultiPolygonField(srid=4326, blank=True, null=True) geom_geometrycollection = models.GeometryCollectionField(srid=4326, blank=True, null=True) attribute_values = JSONField(default=dict) objects = GeoManager() def __str__(self): return str(self.id)
class Monument(models.Model): """ Monument model NOTE: 'geometrie' type is GeometryCollectionField, possibly in future (e.g. for searching) this needs to be split out in various Geometry types (POLYGON, MULTIPOLYGON, LINESTRING). -- aanvulling op stelselpedia -- external_id: id conform AMISExport.xml """ id = models.CharField(max_length=36, primary_key=True) external_id = models.CharField(max_length=36, null=True) monument_aanwijzingsdatum = models.DateField(null=True) architect_ontwerp_monument = models.CharField(max_length=128, null=True) beschrijving_monument = models.TextField(null=True) beschrijving_monument_publiek = models.BooleanField(default=False) monumentcoordinaten = models.PointField(null=True, srid=28992) afbeelding = models.CharField(max_length=36, null=True) oorspronkelijke_functie_monument = models.CharField(max_length=128, null=True) monumentgeometrie = models.GeometryCollectionField(null=True, srid=28992) in_onderzoek = models.CharField(max_length=3, null=True) monumentnummer = models.IntegerField(null=True) monumentnaam = models.CharField(max_length=255, null=True) display_naam = models.CharField(max_length=255, null=True) opdrachtgever_bouw_monument = models.CharField(max_length=128, null=True) bouwjaar_start_bouwperiode_monument = models.IntegerField(null=True) bouwjaar_eind_bouwperiode_monument = models.IntegerField(null=True) redengevende_omschrijving_monument = models.TextField(null=True) redengevende_omschrijving_monument_publiek = models.BooleanField( default=False) monumentstatus = models.CharField(max_length=128, null=True) monumenttype = models.CharField(max_length=128, null=True) heeft_als_grondslag_beperking = models.CharField(max_length=15, null=True) complex = models.ForeignKey(Complex, models.DO_NOTHING, related_name='monumenten', null=True) def __str__(self): if self.display_naam: return self.display_naam if self.monumentnummer: return str(self.monumentnummer) if self.situeringen: return repr(self.situeringen.first()) return "Monument {}".format(self.id) class Meta: ordering = ('external_id', )
class Feature(models.Model): shapefile = models.ForeignKey(Shapefile, on_delete=models.CASCADE) name = models.CharField(max_length=255,blank=True, null=True) geom_point = models.PointField(srid=4326,blank=True, null=True) geom_multipoint = \ models.MultiPointField(srid=4326,blank=True, null=True) geom_multilinestring = \ models.MultiLineStringField(srid=4326,blank=True, null=True) geom_multipolygon = \ models.MultiPolygonField(srid=4326,blank=True, null=True) geom_geometrycollection = \ models.GeometryCollectionField(srid=4326,blank=True,null=True) def __str__(self): return str(self.shapefile)
class Place(models.Model): """場所""" id = models.CharField('ID', max_length=20, primary_key=True) name = models.CharField( '名前', max_length=50, ) # 場所名 division = models.CharField( '区分', max_length=1, choices=(('1', '倉庫'), ('2', '店舗')), default=2, ) # 区分 address = models.CharField( '住所', max_length=100, ) # 住所 point = models.PointField( '地点', null=True, blank=True, ) # length = models.IntegerField('半径', max_length=20, ) # Geomet = models.GeometryField('Geometry', null=True, blank=True, ) # LineStr = models.LineStringField('LineString', null=True, blank=True, ) # Poly = models.PolygonField('Polygon', null=True, blank=True, ) multip = models.MultiPointField( 'MultiPoint', null=True, blank=True, ) multils = models.MultiLineStringField( 'MultiLineString', null=True, blank=True, ) multipo = models.MultiPolygonField( 'MultiPolygon', null=True, blank=True, ) geometryc = models.GeometryCollectionField( 'GeometryCollection', null=True, blank=True, ) def __str__(self): return self.name
class Feature(models.Model): vectorlayer = models.ForeignKey(VectorLayer) geom_point = models.PointField(srid=4326, blank=True, null=True) geom_multipoint = models.MultiPointField(srid=4326, blank=True, null=True) geom_multilinestring = models.MultiLineStringField(srid=4326, blank=True, null=True) geom_multipolygon = models.MultiPolygonField(srid=4326, blank=True, null=True) geom_geometrycollection = models.GeometryCollectionField(srid=4326, blank=True, null=True) objects = models.GeoManager()
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()
class Feature(models.Model): layer = models.ForeignKey(Layer) geometry = models.GeometryCollectionField(srid=3857) properties = JSONField(null=True) @property def verbose_name(self): if self.properties.has_key('name'): return self.properties['name'] elif self.properties.has_key('NAME'): return self.properties['NAME'] else: return self.properties['fid'] def __unicode__(self): return unicode(self.pk)
class DocumentIndex(models.Model): """ Indexed values for a specific document. """ document = models.ForeignKey(Document, related_name='indices') json = jsonb.JSONField(verbose_name="JSON") geometry = models.GeometryCollectionField(blank=True, null=True, geography=True) objects = DocumentIndexManager() class Meta: ordering = ['pk'] verbose_name = 'Index' verbose_name_plural = 'Indices' def __str__(self): return str(self.id) def verbose_name(self): return str(self.json) def format_document_type(self): return self.document.document_type.name format_document_type.short_description = 'Document type' format_document_type.admin_order_field = 'document__document_type__name' def format_document_id(self): if self.document.id is None: return url = reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.object_name.lower()), args=[self.document.id]) return "<a href='%s'>%d</a>" % (url, self.document.id) format_document_id.allow_tags = True format_document_id.short_description = 'Document ID' format_document_id.admin_order_field = 'document__id' def format_index_id(self): if self.id is None: return url = reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.object_name.lower()), args=[self.id]) return "<a href='%s'>%d</a>" % (url, self.id) format_index_id.allow_tags = True format_index_id.short_description = 'Index ID'
class Feature(models.Model): shapefile = models.ForeignKey(Shapefile) geom_point = models.PointField(srid=4326, blank=True, null=True) geom_multipoint = models.MultiPointField(srid=4326, blank=True, null=True) geom_multilinestring = models.MultiLineStringField(srid=4326, blank=True, null=True) geom_multipolygon = models.MultiPolygonField(srid=4326, blank=True, null=True) geom_geometrycollection = models.GeometryCollectionField(srid=4326, blank=True, null=True) objects = models.GeoManager() def __unicode__(self): return str(self.id)
class Infraestructura(models.Model): autor_id = models.ForeignKey(User,null=True,on_delete=models.SET_NULL,db_column='autor_id') id = models.AutoField(primary_key=True) categoria = models.CharField(max_length=250,default=None,blank=False,verbose_name='Categoria') nombre = models.CharField(max_length=250,default=None,blank=False,verbose_name='Nombre') descripcion = models.TextField(default=None,blank=True,verbose_name='Descripción') geom = models.GeometryCollectionField(null=True,verbose_name='Georreferenciación',srid=4326) id_inst = models.ForeignKey(Instituciones,related_name='idInfInstitucion',null=True,on_delete=models.SET_NULL,blank=True,db_column='id_inst') # file will be uploaded to MEDIA_ROOT / uploads ficha_tec = models.FileField(upload_to ='cynr_app/fichas_tecnicas/',blank=True) atributos = models.JSONField(null=True,blank=True) # permite cargar atributos en formato json def __str__(self): return self.nombre class Meta: managed = True db_table = 'infraestructura'
class Geometry(TimeStampedModel, SpatialEntry, PermissionPathMixin, DetailViewMixin): """A holder for geometry vector data.""" name = models.CharField(max_length=1000, blank=True) description = models.TextField(null=True, blank=True) data = models.GeometryCollectionField( srid=DB_SRID) # Can be one or many features # The actual collection is iterable so access is super easy # Can be null if not generated from uploaded ZIP file but something else geometry_archive = models.OneToOneField(GeometryArchive, null=True, on_delete=models.CASCADE) permissions_paths = [('geometry_archive', GeometryArchive)] detail_view_name = 'geometry-entry-detail'