def main(opts): pattern = loads(open(opts.input, "r").read()) extent = loads(open(opts.extent, "r").read()) if not contains.matches(extent.relate(pattern)): print "ERROR: pattern must be contained within the extent" return c = pattern.centroid (xs, ys) = extent.boundary.xy (minx, maxx, miny, maxy) = (min(xs) - c.x, max(xs) - c.x, min(ys) - c.y, max(ys) - c.y) outputFile = open(opts.output, "w") geoms = [] while len(geoms) < opts.number: dx = random.uniform(minx, maxx) dy = random.uniform(miny, maxy) geom = translate(pattern, xoff=dx, yoff=dy) if contains.matches(extent.relate(geom)): # Check that it is within the extent overlap = False for g in geoms: if intersects.matches(g.relate(geom)): overlap = True if overlap == False: geoms.append(geom) for geom in geoms: outputFile.write(dumps(geom) + "\n") outputFile.close()
def main(opts): pattern = loads(open(opts.input, 'r').read()) extent = loads(open(opts.extent, 'r').read()) if not contains.matches(extent.relate(pattern)): print 'ERROR: pattern must be contained within the extent' return c = pattern.centroid (xs, ys) = extent.boundary.xy (minx, maxx, miny, maxy) = (min(xs) - c.x, max(xs) - c.x, min(ys) - c.y, max(ys) - c.y) outputFile = open(opts.output, 'w') geoms = [] while len(geoms) < opts.number: dx = random.uniform(minx, maxx) dy = random.uniform(miny, maxy) geom = translate(pattern, xoff=dx, yoff=dy) if contains.matches(extent.relate(geom)): # Check that it is within the extent overlap = False for g in geoms: if intersects.matches(g.relate(geom)): overlap = True if overlap == False: geoms.append(geom) for geom in geoms: outputFile.write(dumps(geom) + '\n') outputFile.close()
def _relation(self, geom1, geom2): """ Returns the relationship between two geometries. 0 if they are disjoint, 1 if geom2 is completely in geom1, 2 if geom2 is partly in geom1""" relation = geom1.relate(geom2) if not intersects.matches(relation): return 0 # they are disjoint elif contains.matches(relation): return 1 else: # there is some overlap if excluding_interiors.matches(relation): return 0 # overlap only in boundaries, we do not count it else: return 2 # some interior of geom2 is in geom1
def _relation(self, geom1, geom2): """ Returns the relationship between two geometries. 0 if they are disjoint, 1 if geom2 is completely in geom1, 2 if geom2 is partly in geom1""" relation = geom1.relate(geom2) if not intersects.matches(relation): return 0 # they are disjoint elif contains.matches(relation): return 1 else: # there is some overlaps if excluding_interiors.matches(relation): return 0 # overlap only in boundaries, we do not count it else: return 2 # some interior of geom2 is in geom1