def __init__(self,record:dict): self.record = record # self.record['geom'] = 'SRID=4326;'+ self.record['geom'] self.record['geom'] = func.ST_GeomFromText(self.record['geom'],4326) #insert factor to selfrecord self.record = self.insert_dis_factor(self.record) print("insert dis factor to self.record complete") self.show_calculate = False self.setting = { "show_comparetor" : True } #read main factor for prop type from ini # self.appr_rule = read_init("wqs.ini") self.factor_weight = { "location" : 50 , "distance" : [ 10 , 10 , 5 , 5 , 5] , "area" : 15 , } # 5: dis +-300 and area +- 500 self.item_weight_rule = { 5 : [300 ,500], # weight = 5 when distance +-300 4 : [500,800], 3 : [1000,1500] } "where district = " #must in ini file self.comparetor_num = 5 print("start finding ",self.comparetor_num," comparetor") self.comparetors = self.find_all_comparetor(self.record) if self.setting['show_comparetor'] : self.record["comparetors"] = self.comparetors print("finish finding") self.cal_apprisal_price()
def get_by_buffer(self, input_geom): # new_geom = func.ST_GeomFromText(geom) sql = self.model.select().where( func.ST_Intersects( func.ST_setsrid( func.ST_Buffer(func.ST_GeomFromText(input_geom), 0.5, "quad_segs=8"), 4326), func.ST_setsrid(self.model.c.geom, 4326))) result = connection.execute(sql).fetchall() return result
def get_naerby_facility(geom, cat_id, buffer_size=2000): new_records = [] geom = func.ST_GeomFromText(geom, 4326) results = find_distance_to_nearby_cat(geom, cat_id, buffer_size) for result in results: new_record = {} new_record['name'] = result[1] new_record['distance'] = result[0] new_records.append(new_record) return new_records
def get_by_buffer(input_geom, cat_id=None, buffer_size=500): sql = table.model.select().where( and_( func.ST_Intersects( func.ST_setsrid( func.ST_Buffer(func.ST_GeomFromText(input_geom), buffer_size, "quad_segs=8"), 4326), func.ST_setsrid(table.model.c.geom, 4326)), table.model.c.category_id == cat_id)) # new_geom = func.ST_GeomFromText(geom) if cat_id is not None: sql = table.model.select().where( func.ST_Intersects( func.ST_setsrid( func.ST_Buffer(func.ST_GeomFromText(input_geom), buffer_size, "quad_segs=8"), 4326), func.ST_setsrid(table.model.c.geom, 4326))) results = connection.execute(sql).fetchall() return results
def insert_records(json_file_name): # category => Crud table # shp => Crud table category_record = util.readFromJson(json_file_name) shp_records = category_record.pop('records', None) # print(shp_records) category_id = category.insert_record(category_record) for record in shp_records: name = record['name'] print(f" => upload {name}") record['category_id'] = category_id #not sure record['geom'] = func.ST_GeomFromText(record['geom'], 4326) shp.insert_record(record)
def get_by_buffer_in_meter(input_geom, cat_id, buffer_size=100000): print("start finding all buffer") if isinstance(input_geom, str): input_geom = func.ST_GeomFromText(input_geom, 4326) results = get_by_buffer(input_geom, buffer_size) output = [] for record in results: r_record = dict(record.items()) if r_record['category_id'] == cat_id: output.append(r_record) results = buffer_in_meter(output, buffer_size, input_geom) for i in results: i['geom'] = convert_wkb(i['geom']) print("finish finding all cat_id: ", cat_id, "in distance", buffer_size, "meters") return results
def read_category(request): record = json.loads(request) return json.dumps( get_naerby_facility(func.ST_GeomFromText(record['geom'], 4326), record['cat_id'], record['buffer_size']))