from IPython.display import Image
Image(url='http://www.portailsig.org/sites/default/files/zeropoint_logo.png')
import os
os.environ['GISBASE'] = '/Applications/GRASS-6.4.app/Contents/MacOS'
os.environ['PYTHONPATH']="/Applications/GRASS-6.4.app/Contents/MacOS/etc/python/"
os.environ['LD_LIBRARY_PATH']="/Applications/GRASS-6.4.app/Contents/MacOS/lib"
os.environ['GIS_LOCK'] = '$$'
os.environ['GISRC'] = '/Users/martinlaloux/.grassrc6'
import grass.script as grass
simple exemple tiré de GRASS GIS v. 6.4.2: la nouvelle console Python (Shell Python), exemple d'utilisation simple ou avec le module Shapely
gisbase = os.environ['GISBASE']
gisdb="/Users/martinlaloux/grassdata"
location="geol"
mapset="test_python"
import grass.script.setup as gsetup
gsetup.init(gisbase, gisdb, location, mapset)
'/var/folders/vu/vu099NovH-KZpE5TEa83BU+++TI/-Tmp-/tmpoCupAJ'
debligne =grass.read_command("v.to.db", flags="p", map="testgrass", type="line", option="start", units="meters" , quiet=True)
debx=float(debligne.split("|")[1])
deby=float(debligne.split("|")[2])
debz=float(debligne.split("|")[3])
finligne=grass.read_command("v.to.db", flags="p", map="testgrass",type="line", option="end", units="meters", quiet=True)
finx=float(finligne.split("|")[1])
finy=float(finligne.split("|")[2])
finz=float(finligne.split("|")[3])
from shapely.geometry import Point
Point1 = Point(debx,deby)
Point2 = Point(finx,finy)
from shapely.geometry import LineString
line = LineString([Point1,Point2])
%matplotlib inline
print line
LINESTRING (186139.123704173 53082.6541939769, 188199.122798505 53467.7585587325)
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
x, y = line.xy
ax.plot(x, y, color='b')
[<matplotlib.lines.Line2D at 0x1068c4c90>]
load_ext rpy2.ipython
%%R -w 480 -h 480 -u px
library(ggplot2)
dat <- data.frame(x = rnorm(2), y = rnorm(2),
lab = sample(c('deb', 'fin'), 10, replace = TRUE))
x <- ggplot(dat, aes(x = x, y = y, color = lab)) + geom_point() + geom_line()
print(x)
%load_ext oct2py.ipython
%octave -i x x
[[ 186139.12370417 188199.12279851]]
array([[ 186139.12370417, 188199.12279851]])
%octave -i y y
[[ 53082.65419398 53467.75855873]]
array([[ 53082.65419398, 53467.75855873]])
%%octave -s 480,480 -f svg
plot(x,y);
%Rpush x y
%R lm(y~x)$coef
<Matrix - Python:0x121de5c68 / R:0x122224808> [53082.654194, NA_real_, NA_real_, 53467.758559, NA_real_, NA_real_]
Xr = x - x.mean(); Yr = y - y.mean()
pente = (Yr*Yr).sum() / (Xr**2).sum()
interception = x.mean() - x.mean() * pente
(interception, pente)
(180627.92926224536, 0.034948039908857427)
%R resid(lm(y~x)); coef(lm(x~y))
<Matrix - Python:0x107606b48 / R:0x10f824e60> [186139.123704, NA_real_, NA_real_, 188199.122799, NA_real_, NA_real_]
b = %R a=resid(lm(y~x))
print b
[,1] [,2] 1 0 0
v1 = %R plot(x,y); print(summary(lm(y~x))); vv=mean(x)*mean(y)
print 'v1 est égal à :', v1
v2 = %R mean(x)*mean(y)
print 'v2 est égal à:', v2
Response Y1 : Call: lm(formula = Y1 ~ x) Residuals: ALL 1 residuals are 0: no residual degrees of freedom! Coefficients: (2 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) 53083 NA NA NA x1 NA NA NA NA x2 NA NA NA NA Residual standard error: NaN on 0 degrees of freedom Response Y2 : Call: lm(formula = Y2 ~ x) Residuals: ALL 1 residuals are 0: no residual degrees of freedom! Coefficients: (2 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) 53468 NA NA NA x1 NA NA NA NA x2 NA NA NA NA Residual standard error: NaN on 0 degrees of freedom
v1 est égal à: [1] 9971473668 v2 est égal à: [1] 9971473668