def replaceAllByArray(query,data): q = Py.newString(query) spliter = re.compile("[\?]{2}") split = spliter.split(q) sb=[] count = len(split) sb.append(split[0]) idx = 1 while idx<count: sb.append(data[idx-1]) sb.append(split[idx]) idx=idx+1 return ''.join(sb)
def replaceAllByArray(query,data): q = Py.newString(query) spliter = re.compile("[\?]{2}") split = spliter.split(q) sb=[] count = len(split) sb.append(split[0]) idx = 1 while idx<count: sb.append(data[idx-1]) sb.append(split[idx]) idx=idx+1 return ''.join(sb)
def replace(query,data): q = Py.newString(query) spliter = re.compile("[\?]{2}") split = spliter.split(q) return split[0]+data+split[1]
def renderMap(self, connection_parameters=None, sql=None, geom_id_entity=None, geom_entity=None, data_entity=None, map_parameters={}): # Put connection parameters into a java HashMap. params_hashmap = HashMap() for param, value in connection_parameters.items(): if value: params_hashmap.put(param, value) # Get data store. data_store = DataStoreFinder.getDataStore(params_hashmap) # Create VirtualTable from sql. vtable = VirtualTable("vtable", sql) # Set primary key. vtable.setPrimaryKeyColumns([geom_id_entity['ID']]) # metadatata = intententional typo. GT needs to fix the name. vtable.addGeometryMetadatata(geom_entity['ID'], JPolygon, 4326) # Create feature source from virtual table. data_store.addVirtualTable(vtable) feature_source = data_store.getFeatureSource("vtable") # Add styling classes if there was a value entity. if data_entity: # Generate class bounds. num_classes = data_entity.get('num_classes', 25) vmin = float(data_entity.get('min', 0)) vmax = float(data_entity.get('max', 1)) vrange = vmax - vmin class_width = vrange/num_classes classes = [(None, vmin)] for i in range(num_classes): classes.append((vmin + i * class_width, vmin + (i + 1) * class_width)) classes.append((vmax, None)) # Generate style rules for classes. rules = [] for c in classes: rule = self.create_rule(c[0], c[1], vmin, vrange, attr=data_entity['ID']) rules.append(rule) feature_type_style = self.style_factory.createFeatureTypeStyle(rules) style = self.style_factory.createStyle() style.featureTypeStyles().add(feature_type_style) else: style = None # Setup map. gt_map = DefaultMapContext() gt_map.addLayer(feature_source, style) gt_renderer = StreamingRenderer() gt_renderer.setMapContent(gt_map) image_bounds = Rectangle(0, 0, map_parameters.get('WIDTH', 100), map_parameters.get('HEIGHT', 100)) # Set image type based on format. image_format = map_parameters.get('FORMAT', 'image/png') if image_format == 'image/jpeg': image_type = BufferedImage.TYPE_INT_RGB else: image_type = BufferedImage.TYPE_INT_ARGB buffered_image = BufferedImage(image_bounds.width, image_bounds.height, image_type) graphics = buffered_image.createGraphics() # Set background color if not transparent. if not map_parameters.get('TRANSPARENT'): graphics.setPaint(Color.WHITE) graphics.fill(image_bounds) crs = CRS.decode(map_parameters.get('SRS', "EPSG:4326")) bbox = map_parameters.get('BBOX', '-180,-90,180,90') coords = [float(coord) for coord in bbox.split(",")] map_bounds = ReferencedEnvelope(coords[0], coords[2], coords[1], coords[3], crs) gt_renderer.paint(graphics, image_bounds, map_bounds) # Release the JDBC connection and map content. data_store.dispose() gt_renderer.getMapContent().dispose() # Return raw image. byte_array_output_stream = ByteArrayOutputStream() informal_format = re.match('image/(.*)', image_format).group(1) ImageIO.write(buffered_image, informal_format, byte_array_output_stream) byte_array = byte_array_output_stream.toByteArray() raw_image = Py.newString(StringUtil.fromBytes(byte_array)) return raw_image
def replace(query,data): q = Py.newString(query) spliter = re.compile("[\?]{2}") split = spliter.split(q) return split[0]+data+split[1]