Ejemplo n.º 1
0
def convertGeoJson(filename):
    """
    Translates GeoJson files in rijksdriehoeks format to WGS84
    Assumes a valid GeoJson file
    """

    geofile = open(filename)
    jsonFile = simplejson.loads(geofile.read())

    for i in jsonFile["features"]:
        for j in i["geometry"]["coordinates"]:
            for k in j:
                if type(k[0]).__name__=='float':
                    newk = rd2wgs84.convert(k[0], k[1])
                    k[0] = newk[1]
                    k[1] = newk[0]
                else:
                    for l in k:
                        newl = rd2wgs84.convert(l[0], l[1])
                        l[0] = newl[1]
                        l[1] = newl[0]

    newGeofile = open("wgs84." + geofile.name, "w")
    newGeofile.write(simplejson.dumps(jsonFile))
    newGeofile.close()
Ejemplo n.º 2
0
def convertGeoJson(filename):
    """
    Translates GeoJson files in rijksdriehoeks format to WGS84
    Assumes a valid GeoJson file
    """

    geofile = open(filename)
    jsonFile = simplejson.loads(geofile.read())

    for i in jsonFile["features"]:
        for j in i["geometry"]["coordinates"]:
            for k in j:
                if type(k[0]).__name__ == 'float':
                    newk = rd2wgs84.convert(k[0], k[1])
                    k[0] = newk[1]
                    k[1] = newk[0]
                else:
                    for l in k:
                        newl = rd2wgs84.convert(l[0], l[1])
                        l[0] = newl[1]
                        l[1] = newl[0]

    newGeofile = open("wgs84." + geofile.name, "w")
    newGeofile.write(simplejson.dumps(jsonFile))
    newGeofile.close()
Ejemplo n.º 3
0
def main():
    monument_list = bs(req.get(base_url).text)
    urls = parse_href(monument_list.select('td a'))[1:-1]
    urls = [url.split("'")[1] for url in urls]
    for url in urls:
        monument = bs(req.get(monument_url % (url)).text)
        attrs = monument.select('.tabeltype1 td')
        attrs.pop(0)
        attrs.pop(24)
        attrs.pop(42)
        p_attrs = parse_table(attrs)
        url = monument_url % (url)
        print(monument_url % (url))
        x, y = p_attrs['X-Y coörd'].split('-')
        if x and y:
            x, y = int(x), int(y)
            lat, lon = rd_convert.convert(x, y)
            results.append({'url': url,
                            'naam': p_attrs.get('Monumentnaam', None),
                            'lat': lat,
                            'lon': lon,
                            })

    with open('monumenten_best.json', 'w') as dump:
        json.dump(results, dump)
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        '''
        import the given JSON file taking into account city specific settings
        '''

        if len(args) != 2:
            raise CommandError('This commands takes exactly 2 arguments')

        city_name = args[0] # i.e. 'den haag'
        json_file = args[1] # i.e. 'export.geojson'

        city = City.objects.get(name__iexact=city_name)

        if not city:
            raise CommandError('City "%s" does not exist' % city_name)

        try:
            geofile = open(json_file)
            data = json.loads(geofile.read().decode('latin_1')) # somehow latin_1 works more reliably
        except:
            raise CommandError('Could not load: "%s"' % json_file)

        # try and add each 'feature' a.k.a. play thingie to the DB
        for i in data["features"]:
            coords = i["geometry"]["coordinates"]

            # convert from the 'dutch' coordinate system to the more common WGS84 (which Google gets)
            if type(coords[0]).__name__=='float':
                newk = rd2wgs84.convert(coords[0], coords[1])
                lat = newk[0]
                lng = newk[1]

            properties = i["properties"]

            # only add playthings with lat, lng and some properties
            if lat and lng and properties:
                create_or_update(self.stderr, self.stdout, city, properties, lat, lng, options.get('force'))
            else:
                pass

        self.stdout.write('Successfully imported playthings from JSON "%s"\n' % json_file.encode('utf-8'))