Beispiel #1
0
    def test_create_dataset(self):
        ds2 = SpatialiteDriver.create_dataset('created dataset',
                                              columns_definitions=(
                                                  ('name', "TEXT"),
                                                  ('i', 'INTEGER'),
                                                  ('j', "REAL"),
                                              ))
        ds3 = SpatialiteDriver.create_dataset('created empty dataset')

        self.assertListEqual([
            'OGC_FID', 'GEOMETRY', 'name', 'i', 'j'
        ], ds2.resource.schema(
        ), 'empty dataset with four columns should have had four columns, but had {schema}'
                             .format(schema=ds2.resource.schema()))
        self.assertListEqual(
            ['OGC_FID', 'GEOMETRY'], ds3.resource.schema(),
            'empty dataset schema should have had nothing in it, had {schema}'.
            format(schema=ds3.resource.schema()))

        ds3.resource.add_column('name', 'TEXT')
        ds3.resource.add_column('i', 'TEXT')
        ds3.resource.add_column('j', 'TEXT')

        self.assertListEqual(
            ds3.resource.schema(), ['OGC_FID', 'GEOMETRY', 'name', 'i', 'j'],
            "added columns, but they didn't show up right: {schema}".format(
                schema=ds3.resource.schema()))
Beispiel #2
0
    def test_create_dataset_with_parent_geometry(self):
        ds2 = SpatialiteDriver.create_dataset_with_parent_geometry(
            'geometry derived dataset',
            self.ds,
            columns_definitions=(('name', 'TEXT'), ('i', 'INTEGER'), ('j',
                                                                      'REAL')))
        ds3 = SpatialiteDriver.create_dataset_with_parent_geometry(
            'geometry dervied dataset 2', self.ds)
        self.assertListEqual([
            'OGC_FID', 'GEOMETRY', 'name', 'i', 'j'
        ], ds2.resource.schema(
        ), 'empty dataset with three columns should have had three columns, but had {schema}'
                             .format(schema=ds2.resource.schema()))
        self.assertListEqual(
            ['OGC_FID', 'GEOMETRY'], ds3.resource.schema(),
            'empty dataset schema should have had nothing in it, had {schema}'.
            format(schema=ds3.resource.schema()))

        ds3.resource.add_column('name', 'TEXT')
        ds3.resource.add_column('i', 'TEXT')
        ds3.resource.add_column('j', 'TEXT')

        self.assertListEqual(
            ds3.resource.schema(), ['OGC_FID', 'GEOMETRY', 'name', 'i', 'j'],
            "added columns, but they didn't show up right: {schema}".format(
                schema=ds3.resource.schema()))
Beispiel #3
0
def create_dataset_with_parent_geometry(request, slug):
    user = authorize(request)

    title = request.REQUEST.get('title', 'Untitled dataset')
    parent_dataresource = slug
    srid = int(request.REQUEST.get('srid', 4326))
    geometry_type = request.REQUEST.get('geometry_type', 'GEOMETRY')
    columns_definitions = json.loads(request.REQUEST.get('columns_definitions', "{}"))
    columns_definitions = ((key, value) for key, value in columns_definitions.items())
    parent_key = request.REQUEST.get('parent_key', None)
    child_key = request.REQUEST.get('child_key', None)
    csv = None

    if len(request.FILES.keys()) > 0:
        csvfile = NamedTemporaryFile(suffix='csv')
        csvfile.write(request.FILES[request.FILES.keys().next()].read())
        csvfile.flush()
        csv = pandas.DataFrame.from_csv(csvfile.name)

    if 'parent_page' in request.REQUEST:
        parent_page = Page.objects.get(slug=request.REQUEST['parent_page'])
        authorize(request, parent_page, add=True)
    else:
        parent_page = get_data_page_for_user(request.user)

    parent_dataresource = DataResource.objects.get(slug=parent_dataresource)
    authorize(request, parent_page, view=True)

    if csv:
        ds = SpatialiteDriver.join_data_with_existing_geometry(
            title=title,
            parent=parent_page,
            new_data=csv,
            join_field_in_existing_data=parent_key,
            join_field_in_new_data=child_key,
            parent_dataresource=parent_dataresource,
            srid=srid,
            geometry_type=geometry_type,
            owner=request.user
        )
    else:
        ds = SpatialiteDriver.create_dataset_with_parent_geometry(
            title=title,
            parent=parent_page,
            parent_dataresource=parent_dataresource,
            srid=srid,
            columns_definitions=columns_definitions,
            geometry_type=geometry_type,
            owner=request.user
        )

    dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
    dispatch.dataset_created.send(sender=ds, user=user)
    return json_or_jsonp(request, {'path': ds.slug}, code=201)
Beispiel #4
0
def create_dataset_with_parent_geometry(request, slug):
    user = authorize(request)

    title = request.REQUEST.get('title', 'Untitled dataset')
    parent_dataresource = slug
    srid = int(request.REQUEST.get('srid', 4326))
    geometry_type = request.REQUEST.get('geometry_type', 'GEOMETRY')
    columns_definitions = json.loads(request.REQUEST.get('columns_definitions', "{}"))
    columns_definitions = ((key, value) for key, value in columns_definitions.items())
    parent_key = request.REQUEST.get('parent_key', None)
    child_key = request.REQUEST.get('child_key', None)
    csv = None

    if len(request.FILES.keys()) > 0:
        csvfile = NamedTemporaryFile(suffix='csv')
        csvfile.write(request.FILES[request.FILES.keys().next()].read())
        csvfile.flush()
        csv = pandas.DataFrame.from_csv(csvfile.name)

    if 'parent_page' in request.REQUEST:
        parent_page = Page.objects.get(slug=request.REQUEST['parent_page'])
        authorize(request, parent_page, add=True)
    else:
        parent_page = get_data_page_for_user(request.user)

    parent_dataresource = DataResource.objects.get(slug=parent_dataresource)
    authorize(request, parent_page, view=True)

    if csv:
        ds = SpatialiteDriver.join_data_with_existing_geometry(
            title=title,
            parent=parent_page,
            new_data=csv,
            join_field_in_existing_data=parent_key,
            join_field_in_new_data=child_key,
            parent_dataresource=parent_dataresource,
            srid=srid,
            geometry_type=geometry_type,
            owner=request.user
        )
    else:
        ds = SpatialiteDriver.create_dataset_with_parent_geometry(
            title=title,
            parent=parent_page,
            parent_dataresource=parent_dataresource,
            srid=srid,
            columns_definitions=columns_definitions,
            geometry_type=geometry_type,
            owner=request.user
        )

    dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
    dispatch.dataset_created.send(sender=ds, user=user)
    return json_or_jsonp(request, {'path': ds.slug}, code=201)
Beispiel #5
0
    def test_delete_row(self):
        ds2 = SpatialiteDriver.create_dataset('update test dataset',
                                              columns_definitions=(
                                                  ('name', "TEXT"),
                                                  ('i', 'INTEGER'),
                                                  ('j', "REAL"),
                                              ))
        ds2.resource.add_row(name='jeff', i=1, j=2.0, GEOMETRY='POINT(0 0)')
        row = ds2.resource.get_row(1)
        rs = ds2.resource.get_rows(1, limit=100)

        self.assertEqual(
            len(rs),
            1,
            msg='add row failed.  length was (n).'.format(n=len(rs)))

        ds2.resource.delete_row(1)
        rs = ds2.resource.get_rows(1, limit=100)

        self.assertEqual(
            len(rs),
            0,
            msg=
            'delete row should have deleted the row but didnt.  length was (n).'
            .format(n=len(rs)))
Beispiel #6
0
def derive_dataset(request, slug):
    user = authorize(request)

    title = request.REQUEST.get('title', 'Untitled dataset')
    parent_dataresource=slug

    if 'parent_page' in request.REQUEST:
        parent_page = Page.objects.get(slug=request.REQUEST['parent_page'])
        authorize(request, parent_page, add=True)
    else:
        parent_page = get_data_page_for_user(request.user)

    parent_dataresource = DataResource.objects.get(slug=parent_dataresource)
    authorize(request, parent_dataresource, view=True)

    ds = SpatialiteDriver.derive_dataset(
        title=title,
        parent_page=parent_page,
        parent_dataresource=parent_dataresource,
        owner=request.user
    )

    dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
    dispatch.dataset_created.send(sender=DataResource, instance=ds, user=user)
    return json_or_jsonp(request, {'path': ds.slug}, code=201)
Beispiel #7
0
def create_dataset(request):
    user = authorize(request)

    title = request.REQUEST.get('title','Untitled dataset')
    srid = int(request.REQUEST.get('srid', 4326))
    geometry_type=request.REQUEST.get('geometry_type', 'GEOMETRY')
    columns_definitions=json.loads(request.REQUEST.get('columns_definitions', "{}"))
    columns_definitions=((key, value) for key, value in columns_definitions.items())

    if 'parent' in request.REQUEST:
        parent = Page.objects.get(slug=request.REQUEST['parent'])
        authorize(request, parent, add=True)
    else:
        parent = get_data_page_for_user(request.user)

    ds = SpatialiteDriver.create_dataset(
        title=title,
        parent=parent,
        srid=srid,
        geometry_type=geometry_type,
        columns_definitions=columns_definitions,
        owner=request.user
    )

    dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
    dispatch.dataset_created.send(sender=DataResource, instance=ds, user=user)
    return json_or_jsonp(request, {'path' : ds.slug }, code=201)
Beispiel #8
0
def derive_dataset(request, slug):
    user = authorize(request)

    title = request.REQUEST.get('title', 'Untitled dataset')
    parent_dataresource=slug

    if 'parent_page' in request.REQUEST:
        parent_page = Page.objects.get(slug=request.REQUEST['parent_page'])
        authorize(request, parent_page, add=True)
    else:
        parent_page = get_data_page_for_user(request.user)

    parent_dataresource = DataResource.objects.get(slug=parent_dataresource)
    authorize(request, parent_dataresource, view=True)

    ds = SpatialiteDriver.derive_dataset(
        title=title,
        parent_page=parent_page,
        parent_dataresource=parent_dataresource,
        owner=request.user
    )

    dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
    dispatch.dataset_created.send(sender=DataResource, instance=ds, user=user)
    return json_or_jsonp(request, {'path': ds.slug}, code=201)
Beispiel #9
0
def create_dataset(request):
    user = authorize(request)

    title = request.REQUEST.get('title','Untitled dataset')
    srid = int(request.REQUEST.get('srid', 4326))
    geometry_type=request.REQUEST.get('geometry_type', 'GEOMETRY')
    columns_definitions=json.loads(request.REQUEST.get('columns_definitions', "{}"))
    columns_definitions=((key, value) for key, value in columns_definitions.items())

    if 'parent' in request.REQUEST:
        parent = Page.objects.get(slug=request.REQUEST['parent'])
        authorize(request, parent, add=True)
    else:
        parent = get_data_page_for_user(request.user)

    ds = SpatialiteDriver.create_dataset(
        title=title,
        parent=parent,
        srid=srid,
        geometry_type=geometry_type,
        columns_definitions=columns_definitions,
        owner=request.user
    )

    dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
    dispatch.dataset_created.send(sender=DataResource, instance=ds, user=user)
    return json_or_jsonp(request, {'path' : ds.slug }, code=201)
Beispiel #10
0
    def test_derive_dataset(self):
        ds2 = SpatialiteDriver.derive_dataset('derived dataset', self.ds,
                                              self.ds)
        self.assertIsInstance(ds2, DataResource)

        rs = ds2.resource.get_rows(1, 100, geometry_format='wkt')
        self.assertEqual(
            len(rs), 100,
            'derived dataset length {n}. should have been 100'.format(
                n=len(rs)))
    def test_create_dataset(self):
        ds2 = SpatialiteDriver.create_dataset('created dataset', columns_definitions=(
            ('name', "TEXT"),
            ('i' , 'INTEGER'),
            ('j' , "REAL"),
        ))
        ds3 = SpatialiteDriver.create_dataset('created empty dataset')

        self.assertListEqual(['OGC_FID', 'GEOMETRY','name','i','j'], ds2.resource.schema(),
             'empty dataset with four columns should have had four columns, but had {schema}'.format(
                 schema=ds2.resource.schema()))
        self.assertListEqual(['OGC_FID', 'GEOMETRY'], ds3.resource.schema(),
             'empty dataset schema should have had nothing in it, had {schema}'.format(schema=ds3.resource.schema()))

        ds3.resource.add_column('name', 'TEXT')
        ds3.resource.add_column('i', 'TEXT')
        ds3.resource.add_column('j', 'TEXT')

        self.assertListEqual(ds3.resource.schema(), ['OGC_FID', 'GEOMETRY','name','i','j'],
             "added columns, but they didn't show up right: {schema}".format(schema=ds3.resource.schema()))
    def test_add_row(self):
        ds2 = SpatialiteDriver.create_dataset('update test dataset', columns_definitions=(
            ('name', "TEXT"),
            ('i', 'INTEGER'),
            ('j', "REAL"),
        ))
        ds2.resource.add_row(name='jeff', i=1, j=2.0, GEOMETRY='POINT(0 0)')
        row = ds2.resource.get_row(1)

        self.assertEqual(row['name'], 'jeff', msg='add should have added jeff, but name was {name}'.format(
            name=row['name']
        ))
    def test_create_dataset_with_parent_geometry(self):
        ds2 = SpatialiteDriver.create_dataset_with_parent_geometry(
            'geometry derived dataset',
            self.ds,
            columns_definitions=(('name', 'TEXT'), ('i', 'INTEGER'), ('j', 'REAL'))
        )
        ds3 = SpatialiteDriver.create_dataset_with_parent_geometry(
            'geometry dervied dataset 2',
            self.ds
        )
        self.assertListEqual(['OGC_FID', 'GEOMETRY', 'name', 'i', 'j'], ds2.resource.schema(),
                             'empty dataset with three columns should have had three columns, but had {schema}'.format(
                                 schema=ds2.resource.schema()))
        self.assertListEqual(['OGC_FID', 'GEOMETRY'], ds3.resource.schema(),
                             'empty dataset schema should have had nothing in it, had {schema}'.format(
                                 schema=ds3.resource.schema()))

        ds3.resource.add_column('name', 'TEXT')
        ds3.resource.add_column('i', 'TEXT')
        ds3.resource.add_column('j', 'TEXT')

        self.assertListEqual(ds3.resource.schema(), ['OGC_FID', 'GEOMETRY', 'name', 'i', 'j'],
                             "added columns, but they didn't show up right: {schema}".format(schema=ds3.resource.schema()))
Beispiel #14
0
    def test_add_row(self):
        ds2 = SpatialiteDriver.create_dataset('update test dataset',
                                              columns_definitions=(
                                                  ('name', "TEXT"),
                                                  ('i', 'INTEGER'),
                                                  ('j', "REAL"),
                                              ))
        ds2.resource.add_row(name='jeff', i=1, j=2.0, GEOMETRY='POINT(0 0)')
        row = ds2.resource.get_row(1)

        self.assertEqual(
            row['name'],
            'jeff',
            msg='add should have added jeff, but name was {name}'.format(
                name=row['name']))
    def test_delete_row(self):
        ds2 = SpatialiteDriver.create_dataset('update test dataset', columns_definitions=(
            ('name', "TEXT"),
            ('i', 'INTEGER'),
            ('j', "REAL"),
        ))
        ds2.resource.add_row(name='jeff', i=1, j=2.0, GEOMETRY='POINT(0 0)')
        row = ds2.resource.get_row(1)
        rs = ds2.resource.get_rows(1, limit=100)

        self.assertEqual(len(rs), 1, msg='add row failed.  length was (n).'.format(
            n=len(rs)
        ))

        ds2.resource.delete_row(1)
        rs = ds2.resource.get_rows(1, limit=100)

        self.assertEqual(len(rs), 0, msg='delete row should have deleted the row but didnt.  length was (n).'.format(
            n=len(rs)
        ))
    def test_derive_dataset(self):
        ds2 = SpatialiteDriver.derive_dataset('derived dataset',self.ds, self.ds)
        self.assertIsInstance(ds2, DataResource)

        rs = ds2.resource.get_rows(1, 100, geometry_format='wkt')
        self.assertEqual(len(rs), 100, 'derived dataset length {n}. should have been 100'.format(n=len(rs)))