require(aRT)

con=openConn(user="pedro", dbms="mysql")
if(any(showDbs(con) == "recife")) deleteDb(con, "recife", force=T)
db=createDb(con, "recife")
data(recife.districts)
data(recife.points)
data(recife.sewers)
#plot(recife.districts, col="red", xlab="", ylab="")
#plot(recife.points, add=T)
#plot(recife.districts, col="gray", lty=0, xlab="", ylab="")
#plot(recife.sewers, add=T, col="blue")
ldistricts = createLayer(db, "districts")
lpoints    = createLayer(db, "points")
lsewers    = createLayer(db, "sewers")
		cat("created layer\n")
#addLines (lsewers,    as.SpatialLines(recife.sewers))
addPolygons (ldistricts, as.SpatialRings(recife.districts))
#addPoints(lpoints,    as.SpatialPoints(recife.points))
#t = createTable(lsewers,    "sewers", genid=T)
t = createTable(ldistricts, "districts", genid=T)
#t = createTable(lpoints,    "points", genid=T)
lcity=createLayer(db, "city")
#getMetric(lcity, "area")
#getMetric(lcity, "length")


###################################################
### chunk number 14: getMetric2
###################################################
sum(getMetric(ldistricts, "area")$area)
#$


###################################################
### chunk number 15: getRelation
###################################################
rel1=getRelation(ldistricts, "contains", lpoints)
rel2=getRelation(ldistricts, "touches", id=rel1)

stop("FIM!")
###################################################
### chunk number 16: 
###################################################
plot(recife.districts, col="gray", lty=0, xlab="", ylab="")
plot(recife.districts, col="green", add=T, id=rel2)
plot(recife.districts, col="yellow", add=T, id=rel1)


###################################################
### chunk number 17: getRelation2
###################################################
rel3=getRelation(lsewers, "crosses", layer=ldistricts, id=rel1)
rel4=getRelation(lsewers, "within",  layer=ldistricts, id=rel1)


###################################################
### chunk number 18: 
###################################################
plot(recife.districts, col="gray", lty=0, id=rel1, xlab="", ylab="")
plot(recife.districts, col="gray", lty=0, add=T)
plot(recife.districts, col="yellow", lty=0, id=rel1, add=T)
plot(recife.sewers, add=T)
plot(recife.sewers, add=T, col="green", id=rel3)
plot(recife.sewers, add=T, col="red", id=rel4)


