<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2
import json
from geojson import Feature, Point, FeatureCollection


# Database Connection Info
db_host = "localhost"
db_user = "postgres"
db_passwd = "<PASSWORD>"
db_database = "py_geoan_cb"
db_port = "5432"

conn = psycopg2.connect(host=db_host, user=db_user, port=db_port, password=<PASSWORD>, database=db_database)

cur = conn.cursor()

buffer_query = """select ST_AsGeoJSON(ST_Buffer(wkb_geometry, 100)) as geom, name, country, altitude from geodata.highest_mountains where ogc_fid = 2; """

res = cur.execute(buffer_query)

dbRows = cur.fetchall()

new_geom_collection = []

for each_geom in dbRows:
    # my_feature = Feature(geometry=each_geom)
    geom = each_geom[0]
    name = each_geom[1]
    country = each_geom[2]
    altitude = each_geom[3]


    featureCollection = {"type": "FeatureCollection", "features": []}
    #currentPoiCat = {"featureCollection": featureCollection}


    #geomJson = json.loads(geom)
    item = {
        "type": "Feature",
        "properties":
            {
                "name": name,
                "country": country,
                "altitude": altitude
            },
        "geometry": geom
    }
    featureCollection['features'].append(item)
    #currentPoiCat['featureCollection']['features'].append(item)


# FeatureCollection([my_feature, my_other_feature])
#my_geojson = FeatureCollection(new_geom_collection) # doctest: +ELLIPSIS


# save geojson to file on disk
output_geojson_buf= "../geodata/out_buff_100m.geojson"

def write_geojson():
    fo = open(output_geojson_buf, "w")
    fo.write(json.dumps(featureCollection))
    fo.close()

# run the download and create new file to test, download the json file and compare to current json
write_geojson()

# close cursor
cur.close()

# We are using an InnoDB tables so we need to commit the transaction
conn.commit()

#close connection
conn.close()
<commit_msg>update to use schools buf and st_transform<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2
import json
import geojson
from geojson import Feature, Polygon, Point, FeatureCollection


# Database Connection Info
db_host = "localhost"
db_user = "postgres"
db_passwd = "<PASSWORD>"
db_database = "py_geoan_cb"
db_port = "5432"

conn = psycopg2.connect(host=db_host, user=db_user, port=db_port, password=<PASSWORD>, database=db_database)

cur = conn.cursor()

buffer_query = """select ST_AsGeoJSON(ST_Transform(ST_Buffer(wkb_geometry, 100),4326)) as geom, name
               from geodata.schools"""

# SELECT ST_Transform(ST_GeomFromText('POLYGON((7))',2249),4326) As wgs_geom

res = cur.execute(buffer_query)

dbRows = cur.fetchall()

new_geom_collection = []

for each_poly in dbRows:
    geom = each_poly[0]
    geoj = geojson.loads(geom)
    myfeat = Feature(geometry=geoj)
    new_geom_collection.append(myfeat)

foo = FeatureCollection(new_geom_collection)

# for each_geom in dbRows:
#     # my_feature = Feature(geometry=each_geom)
#     geom = each_geom[0]
#     name = each_geom[1]
#     country = each_geom[2]
#     altitude = each_geom[3]
#
#     featureCollection = {"type": "FeatureCollection", "features": []}
#     # currentPoiCat = {"featureCollection": featureCollection}
#
#
#     #geomJson = json.loads(geom)
#     item = {
#         "type": "Feature",
#         "properties":
#             {
#                 "name": name,
#                 "country": country,
#                 "altitude": altitude
#             },
#         "geometry": geom
#     }
#     featureCollection['features'].append(item)
#     #currentPoiCat['featureCollection']['features'].append(item)

#new_geom_collection.append(featureCollection)
# FeatureCollection([my_feature, my_other_feature])
# my_geojson = FeatureCollection(new_geom_collection) # doctest: +ELLIPSIS


# save geojson to file on disk
output_geojson_buf = "../geodata/out_buff_100m.geojson"


def write_geojson():
    fo = open(output_geojson_buf, "w")
    fo.write(json.dumps(foo))
    fo.close()

# run the download and create new file to test, download the json file and compare to current json
write_geojson()

# close cursor
cur.close()

#close connection
conn.close()

{'fraction_non_alphanumeric': 0.12381178707224334, 'fraction_numerical': 0.01164448669201521, 'mean_word_length': 3.8658959537572253, 'pattern_counts': {'":': 18, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3848566', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1392, 'n_words': 310}